main
test-branch
| Rev | Line | |
|---|
| [b28f397] | 1 | /**
|
|---|
| 2 | * online source: http://static.msi.umn.edu/tutorial/scicomp/general/MPI/workshop_MPI/src/alltoall/main.html
|
|---|
| 3 | */
|
|---|
| 4 | #include <stdio.h>
|
|---|
| 5 | #include "mpi.h"
|
|---|
| 6 |
|
|---|
| 7 | int main( int argc, char **argv )
|
|---|
| 8 | {
|
|---|
| 9 | int send[4], recv[4];
|
|---|
| 10 | int rank, size, k;
|
|---|
| 11 |
|
|---|
| 12 | MPI_Init( &argc, &argv );
|
|---|
| 13 | MPI_Comm_rank( MPI_COMM_WORLD, &rank );
|
|---|
| 14 | MPI_Comm_size( MPI_COMM_WORLD, &size );
|
|---|
| 15 |
|
|---|
| 16 | if (size != 4) {
|
|---|
| 17 | printf("Error!:# of processors must be equal to 4\n");
|
|---|
| 18 | printf("Programm aborting....\n");
|
|---|
| 19 | MPI_Abort(MPI_COMM_WORLD, 1);
|
|---|
| 20 | }
|
|---|
| 21 | for (k=0;k<size;k++) send[k] = (k+1) + rank*size;
|
|---|
| 22 |
|
|---|
| 23 | printf("%d : send = %d %d %d %d\n", rank, send[0], send[1], send[2], send[3]);
|
|---|
| 24 |
|
|---|
| [6e48678] | 25 | MPI_Alltoall(send, 1, MPI_INT, recv, 1, MPI_INT, MPI_COMM_WORLD);
|
|---|
| [b28f397] | 26 |
|
|---|
| 27 | printf("%d : recv = %d %d %d %d\n", rank, recv[0], recv[1], recv[2], recv[3]);
|
|---|
| 28 |
|
|---|
| 29 | MPI_Finalize();
|
|---|
| 30 | return 0;
|
|---|
| 31 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.