This commit is contained in:
Michael Zhang 2023-10-31 04:43:40 +00:00
parent 06d3e930ec
commit 7793d5b447

View file

@ -1,6 +1,7 @@
#include <mpi.h> #include <mpi.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h>
#include <unistd.h> #include <unistd.h>
// https://stackoverflow.com/a/75458495 // 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_FORWARDS 1
#define ORDER_BACKWARDS 2 #define ORDER_BACKWARDS 2
#define CTL_SIZE 4 #define CTL_SIZE 4
@ -59,12 +66,15 @@ int main(int argc, char **argv) {
srand(rank + 1); srand(rank + 1);
for (int i = 0; i < n_over_p; ++i) { 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]; int new_integers[n_over_p];
recursive_quicksort(integers, n, n_over_p, n_over_p, new_integers, recursive_quicksort(integers, n, n_over_p, n_over_p, new_integers,
MPI_COMM_WORLD); 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 // The first node is responsible for collecting all the data and then
// printing it out to the file // printing it out to the file