Commit f29891e9 authored by hasan.bahjat's avatar hasan.bahjat 💬

Update MPI_Allrduce.c Add Beautiifull Print with usefull info, Add Time Ellapsed

parent 22d51672
...@@ -78,11 +78,27 @@ int main(int argc, char** argv) { ...@@ -78,11 +78,27 @@ int main(int argc, char** argv) {
//[1] Use the naive implementation of MPI_Allreduce //[1] Use the naive implementation of MPI_Allreduce
int global_value_naive = 0; int global_value_naive = 0;
naive_allreduce(local_value, global_value_naive, MPI_COMM_WORLD);
printf("[Worker @ %d] I received global sum (naive): %d \n",rank, global_value_naive); // Start timing
double start_time_naive = MPI_Wtime();
// naive MPI All Reduce
naive_allreduce(
local_value,
global_value_naive,
MPI_COMM_WORLD
);
// End timing
double end_time_naive = MPI_Wtime();
double time_naive = end_time_naive - start_time_naive;
printf("[Worker @ %d] My Naive MPI_Allreduce: Global sum = %d, Time = %.6f seconds\n",
rank, global_value_naive, time_naive);
// [2] Use the built-in MPI_Allreduce for comparison // [2] Use the built-in MPI_Allreduce for comparison
int global_value_builtin = 0; int global_value_builtin = 0;
// Start timing
double start_time_builtin = MPI_Wtime();
// Mpi Alllreduce buld in // Mpi Alllreduce buld in
MPI_Allreduce( MPI_Allreduce(
&local_value, &local_value,
...@@ -91,8 +107,12 @@ int main(int argc, char** argv) { ...@@ -91,8 +107,12 @@ int main(int argc, char** argv) {
MPI_SUM, MPI_SUM,
MPI_COMM_WORLD MPI_COMM_WORLD
); );
// End timing
double end_time_builtin = MPI_Wtime();
double time_builtin = end_time_builtin - start_time_builtin;
printf("[Worker @ %d] I received global sum (MPI_Allreduce): %d \n" ,rank, global_value_builtin ); printf("[Worker @ %d] Built-in MPI_Allreduce: Global sum = %d, Time = %.6f seconds\n",
rank, global_value_builtin, time_builtin);
// Fina;ize // Fina;ize
MPI_Finalize(); MPI_Finalize();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment