diff --git a/assignments/02/qs_mpi.c b/assignments/02/qs_mpi.c index 5ba7d4d..3b175ad 100644 --- a/assignments/02/qs_mpi.c +++ b/assignments/02/qs_mpi.c @@ -1,6 +1,7 @@ #include #include #include +#include #include // https://stackoverflow.com/a/75458495 @@ -18,6 +19,12 @@ void __check_mpi_error(const char *file, const int line, const int n) { } } +double monotonic_seconds() { + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return ts.tv_sec + ts.tv_nsec * 1e-9; +} + #define ORDER_FORWARDS 1 #define ORDER_BACKWARDS 2 #define CTL_SIZE 4 @@ -59,12 +66,15 @@ int main(int argc, char **argv) { srand(rank + 1); for (int i = 0; i < n_over_p; ++i) { - integers[i] = rand() % 101; + integers[i] = rand(); } + double start = monotonic_seconds(); int new_integers[n_over_p]; recursive_quicksort(integers, n, n_over_p, n_over_p, new_integers, MPI_COMM_WORLD); + double end = monotonic_seconds(); + printf("Sort Time: %0.04fs\n", end - start); // The first node is responsible for collecting all the data and then // printing it out to the file