main
test-branch
| Line | |
|---|
| 1 | /**
|
|---|
| 2 | * This program has an error because not all processes
|
|---|
| 3 | * execute MPI_Barrier and MPI_Scatter in the same order.
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | #include<mpi.h>
|
|---|
| 7 | #include<stdio.h>
|
|---|
| 8 | #include<stdlib.h>
|
|---|
| 9 |
|
|---|
| 10 | int main(int argc, char* argv[]){
|
|---|
| 11 | int rank;
|
|---|
| 12 | int procs;
|
|---|
| 13 | int* sendbuf, *rcvbuf;
|
|---|
| 14 |
|
|---|
| 15 | MPI_Init(&argc,&argv);
|
|---|
| 16 | MPI_Comm_size(MPI_COMM_WORLD, &procs);
|
|---|
| 17 | MPI_Comm_rank(MPI_COMM_WORLD, &rank);
|
|---|
| 18 |
|
|---|
| 19 | sendbuf = (int*)malloc(sizeof(int)*procs);
|
|---|
| 20 | rcvbuf = (int*)malloc(sizeof(int));
|
|---|
| 21 | if(rank%2){
|
|---|
| 22 | MPI_Scatter(sendbuf, 1, MPI_INT, rcvbuf, 1, MPI_INT, 0, MPI_COMM_WORLD);
|
|---|
| 23 | MPI_Bcast(sendbuf, 1, MPI_INT, 0, MPI_COMM_WORLD);
|
|---|
| 24 | }else{
|
|---|
| 25 | MPI_Bcast(sendbuf, 1, MPI_INT, 0, MPI_COMM_WORLD);
|
|---|
| 26 | MPI_Scatter(sendbuf, 1, MPI_INT, rcvbuf, 1, MPI_INT, 0, MPI_COMM_WORLD);
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | //printf("process %d receivs %d\n", rank, *rcvbuf);
|
|---|
| 30 | free(sendbuf);
|
|---|
| 31 | free(rcvbuf);
|
|---|
| 32 | MPI_Finalize();
|
|---|
| 33 | exit(0);
|
|---|
| 34 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.