forked from sstsimulator/sst-elements
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
34 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,52 +44,35 @@ Questions? Contact [email protected] | |
|
||
#define ssthg_app_name reduce | ||
|
||
#include <stddef.h> | ||
#include <stdio.h> | ||
#include <iostream> | ||
|
||
#include <mask_mpi.h> | ||
#include <mercury/common/skeleton.h> | ||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
MPI_Init(&argc, &argv); | ||
|
||
// Get number of processes and check that 8 processes are used | ||
int size; | ||
int size, rank; | ||
MPI_Comm_size(MPI_COMM_WORLD, &size); | ||
if(size != 8) | ||
{ | ||
printf("This application is meant to be run with 8 MPI processes.\n"); | ||
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); | ||
} | ||
|
||
// Get my rank | ||
int my_rank; | ||
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); | ||
MPI_Comm_rank(MPI_COMM_WORLD, &rank); | ||
|
||
// Define my value | ||
int values[8]; | ||
for(int i = 0; i < 8; i++) | ||
{ | ||
values[i] = my_rank; | ||
int* values = new int[size]; | ||
for(int i = 0; i < size; i++) { | ||
if(i <= rank) | ||
values[i] = 0; | ||
else | ||
values[i] = 1; | ||
} | ||
printf("Process %d, my value = %d\n", my_rank, values[my_rank]); | ||
for (int i = 0; i < 8; i++) { | ||
printf("%d ", values[i]); | ||
} | ||
printf("\n"); | ||
|
||
MPI_Barrier(MPI_COMM_WORLD); | ||
|
||
int recv_values[8]; | ||
MPI_Reduce(values, recv_values, 8, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); | ||
if (my_rank == 0) { | ||
if (recv_values[0] == recv_values[7] && recv_values[0] == 28) | ||
printf("SUCCESS! %d\n",recv_values[0]); | ||
int* recv_values = new int[size]; | ||
MPI_Reduce(values, recv_values, size, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); | ||
if(rank == 0) { | ||
for(int i = 0; i < size; ++i) { | ||
printf("recv_values[%d]=%d\n",i, recv_values[i]); | ||
} | ||
} | ||
|
||
MPI_Finalize(); | ||
|
||
return EXIT_SUCCESS; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
recv_values[0]=0 | ||
recv_values[1]=1 | ||
recv_values[2]=2 | ||
recv_values[3]=3 | ||
recv_values[4]=4 | ||
recv_values[5]=5 | ||
recv_values[6]=6 | ||
recv_values[7]=7 | ||
Simulation is complete, simulated time: 1.21395 us |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters