diff --git a/src/sst/elements/ariel/tests/testMPI/reduce.cc b/src/sst/elements/ariel/tests/testMPI/reduce.cc index 81ea10f484..55c59b1c3f 100644 --- a/src/sst/elements/ariel/tests/testMPI/reduce.cc +++ b/src/sst/elements/ariel/tests/testMPI/reduce.cc @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -7,6 +8,7 @@ #include "arielapi.h" #define DEBUG 0 +#define TIMING 0 int main(int argc, char* argv[]) { @@ -24,7 +26,6 @@ int main(int argc, char* argv[]) { exit(1); } - int rank = 0; int nranks = 0; @@ -46,13 +47,30 @@ int main(int argc, char* argv[]) { len = len / nranks; + FILE *output = stdout; + + if (argc > 2) { + int len = strlen(argv[2]) + 12;// Space for underscore, plus up to a 10 digit integer, plus the null character + char *outfile = (char*)malloc(len); + if (!outfile) { + printf("Error allocating space for filename\n"); + } + snprintf(outfile, len, "%s_%d", argv[2], rank); + + output = fopen(outfile, "w"); + if (!output) { + printf("Unable to open %s\n", outfile); + exit(1); + } + } + + int nthreads = omp_get_max_threads(); #if DEBUG printf("Running on %d ranks, %d threads per rank\n", nranks, nthreads); #endif - // Initialize int *vec = (int*) malloc(sizeof(int) * len); for (int i = 0; i < len; i++) { @@ -60,23 +78,27 @@ int main(int argc, char* argv[]) { } ariel_enable(); + +#if TIMING auto begin = std::chrono::high_resolution_clock::now(); +#endif + long int sum = 0; #pragma omp parallel for reduction(+:sum) for (int i = 0; i < len; i++) { sum += vec[i]; } + +#if TIMING auto end = std::chrono::high_resolution_clock::now(); auto duration = std::chrono::duration_cast(end-begin).count(); if (rank == 0) { std::cout << nranks << " " << nthreads << " " << duration/1000000 << "\n"; } - ariel_disable(); - -#if DEBUG - printf("Rank %d: sum is %ld\n", rank, sum); #endif + ariel_disable(); + long int tot = 0; MPI_Allreduce( &sum, @@ -86,11 +108,7 @@ int main(int argc, char* argv[]) { MPI_SUM, MPI_COMM_WORLD); - -#if DEBUG - printf("Rank %d: tot is %ld\n", rank, tot); -#endif - + fprintf(output, "Rank %d partial sum is %ld, total sum is %d\n", rank, sum, tot); MPI_Barrier(MPI_COMM_WORLD); if (rank == 0) {