1.23
2.0
acw/focus-triggers
main
test-branch
| Line | |
|---|
| 1 | #include <mpi.h>
|
|---|
| 2 | #include <stdio.h>
|
|---|
| 3 |
|
|---|
| 4 | void main(int argc, char * argv[]){
|
|---|
| 5 |
|
|---|
| 6 | int nprocs, rank;
|
|---|
| 7 | int value;
|
|---|
| 8 |
|
|---|
| 9 | MPI_Init(&argc, &argv);
|
|---|
| 10 | MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
|
|---|
| 11 | MPI_Comm_rank(MPI_COMM_WORLD, &rank);
|
|---|
| 12 |
|
|---|
| 13 | if(nprocs < 2){
|
|---|
| 14 | printf("The program needs more than 2 processes.\n");
|
|---|
| 15 | MPI_Finalize();
|
|---|
| 16 | return;
|
|---|
| 17 | }else{
|
|---|
| 18 | MPI_Allreduce(&rank, &value, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
|
|---|
| 19 | printf("I'm process %d, my value is %d \n", rank, value);
|
|---|
| 20 | MPI_Finalize();
|
|---|
| 21 | return;
|
|---|
| 22 | }
|
|---|
| 23 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.