+ if (options.output != NULL) // An output file was specified...
+ {
+ FILE * save = fopen(options.output, "w");
+ if (save == NULL)
+ perror("Couldn't save universe to file.");
+ else
+ {
+ fprintf(save, "# Final field:\n");
+ for (unsigned i = 0; i < universe.N; ++i) // Print all bodies to the file
+ {
+ Body_Print(universe.body+i, save);
+ }
+ fclose(save);
+ }
+
+ }
+ free(universe.body); // Cleanup memory used for bodies
+
+}
+
+/**
+ * @function DisplayStatistics
+ * @purpose Display useful information about the computations done,
+ * - Total number of steps computed
+ * - Time in seconds elapsed
+ * - Clock cycles executed
+ * - Equivelant time for a single thread to execute same number of clock cycles
+ */
+void DisplayStatistics()
+{
+ clock_t end = clock();
+ struct timeval end_time;
+ if (gettimeofday(&end_time, NULL) != 0)
+ {
+ perror("Couldn't get time of day.\n");
+ return;
+ }
+ float runtime = (float)(end_time.tv_sec-options.start_time.tv_sec) + (float)(end_time.tv_usec-options.start_time.tv_usec) / 1.0e6;
+ float clock_time = (float)(end - options.start_clock) / (float)(CLOCKS_PER_SEC);
+ printf("%u\t%f\t%u\t%f\n", universe.steps, runtime, (unsigned)(end - options.start_clock), clock_time);