diff --git a/documents/references.md b/documents/references.md index 563bc86f913c973a022dd7c9c613205c4e10658f..f8a407eb959c93b01dbaa9b55e1cac1e23edc0a6 100644 --- a/documents/references.md +++ b/documents/references.md @@ -67,3 +67,9 @@ Most parallelization logic is from the book "Introduction to Parallel Programmin #### Constants Between Files * <https://stackoverflow.com/a/15531238> * <https://stackoverflow.com/a/5499530> + +#### Tracking Time Elapsed +<https://stackoverflow.com/a/2150334> + +#### Display Percent Sign in Printf +<https://stackoverflow.com/a/1860164> diff --git a/src/main.c b/src/main.c index 28f6f194c5a9e124e717f833a5de98f1abfc8b45..82f621771bc115a3b4eed8faf6a674db0efab91b 100644 --- a/src/main.c +++ b/src/main.c @@ -18,6 +18,7 @@ #include <stdlib.h> #include <string.h> #include <sys/sysinfo.h> +#include <sys/time.h> #include <unistd.h> // User Import Headers. @@ -46,6 +47,9 @@ int total_loads; * Program's main. Initialized and runs program. */ int main(int argc, char* argv[]) { + struct timeval start_time, end_time; + double elapsed_time = 0; + int expected_time_lapse = 0; // Initialize thread communication. MPI_Init(&argc, &argv); @@ -55,13 +59,15 @@ int main(int argc, char* argv[]) { if (process_rank == 0) { printf("Initializing program.\n"); printf("\n"); + + // Get execution start time for program. + gettimeofday(&start_time, NULL); } // Validate program args. validate_args(argc, argv); // If we got this far, then args are valid. Proceed with program. - // total_processors = get_nprocs(); // Display args. if (process_rank == 0) { @@ -79,7 +85,8 @@ int main(int argc, char* argv[]) { printf(" %i Processors in Use\n", total_processors); printf("\n"); printf(" Expected total execution time with ideal processor usage (ignoring unused processors):\n"); - printf(" (Work / Processor Count) = %i Minutes\n", (seconds_active_work / 60 / total_processors)); + expected_time_lapse = seconds_active_work / total_processors; + printf(" (Work / Processor Count) = %i Minutes\n", (expected_time_lapse / 60)); printf("\n"); } @@ -87,10 +94,17 @@ int main(int argc, char* argv[]) { MPI_Barrier(MPI_COMM_WORLD); // Run program. - // display_max_types(); run_program(); if (process_rank == 0) { + // Calculate total time executing program. + gettimeofday(&end_time, NULL); + elapsed_time = end_time.tv_sec - start_time.tv_sec; + + printf("Elapsed Time: %g s.\n", elapsed_time); + printf("Expected Time: %i s\n", expected_time_lapse); + printf("Efficiency (expected time / actual time): %g%%", ((expected_time_lapse / elapsed_time) * 100)); + printf("\n"); printf("Terminating program.\n"); }