Parallel Programming - Final version
[matches/honours.git] / course / semester2 / pprog / assignment1 / single-thread / main.c
index e55c75f..174e005 100644 (file)
@@ -47,9 +47,11 @@ int main(int argc, char** argv)
        options.num_steps = -1; // Negative values => simulation runs forever unless otherwise specified
        options.timeout = -1;
        options.draw_graphics = true;
-       options.pedantic_graphics = false;
+       options.pedantic_graphics = true;
        options.print_positions = false;
        options.verbosity = 0;
+       options.theta = 0.50;
+       options.random = 0;
 
        //If there are no arguments, print information about usage
        if (argc == 1)
@@ -64,7 +66,7 @@ int main(int argc, char** argv)
        HandleArguments(argc, argv);
        
        //Check there is an initial field.
-       if (options.input == NULL)
+       if (options.input == NULL && options.random <= 0)
        {
                fprintf(stderr, "Usage: %s [OPTIONS] field\n", argv[0]);
                fprintf(stderr, " (You did not provide a file for the initial field of bodies)\n");
@@ -76,7 +78,11 @@ int main(int argc, char** argv)
        signal(SIGINT, Interrupt); //Handle SIGINT signals
        atexit(Universe_Cleanup); //On exit, cleanup universe (and write positions of bodies to file if supplied).
        atexit(DisplayStatistics); //On exit, print information about the computations done
-       System_Init(&universe,options.input); //Initialise the universe from the initial field
+       if (options.input != NULL)
+               System_Init(&universe,options.input); //Initialise the universe from the initial field
+       else
+               System_Random(&universe, options.random); //Randomly create bodies
+       
        
        //Setup the time of day at which the simulation starts
        if (gettimeofday(&(options.start_time), NULL) != 0)
@@ -152,6 +158,14 @@ void HandleArguments(int argc, char ** argv)
                                        exit(EXIT_FAILURE);
                                }                               
                                break;
+                       case 'r': //Random initial field
+                               IntegerArgument(&i, argc, argv, &(options.random), NULL);
+                               if (options.random < 0)
+                               {
+                                       fprintf(stderr, "Require a positive integer number of bodies (-%c %s is invalid).", 'r', argv[i]);
+                                       exit(EXIT_FAILURE);
+                               }
+                               break;
                        case 'g': //Graphics switch
                                options.draw_graphics = !options.draw_graphics;
                                break;
@@ -174,6 +188,21 @@ void HandleArguments(int argc, char ** argv)
                                        fprintf(stderr, "Warning: %s switch has no effect in the single threaded program.\n", argv[i]);
                                        #endif //SINGLE_THREADED
 
+                               }
+                               else if (strcmp(argv[i]+2, "theta") == 0)
+                               {
+                                       FloatArgument(&i, argc, argv, &(options.theta));
+                                       #ifndef BARNES_HUT
+                                       fprintf(stderr, "Warning: %s switch only works in Barnes Hut version.\n", argv[i-1]);
+                                       #else
+                                       if (options.theta < 0)
+                                       {
+                                               fprintf(stderr, "Require a theta value greater or equal to zero (%s %s is invalid).\n", argv[i-1], argv[i]);
+                                               exit(EXIT_FAILURE);
+                                       }
+                                       
+                                       #endif //BARNS_HUT
+                                       
                                }
                                else
                                {

UCC git Repository :: git.ucc.asn.au