Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <mpi.h>
- #include <time.h>
- void drukuj(int id, int numprocs, int *array, int size)
- {
- int i,n;
- //printf("%d : ",id);
- for(n = 0; n < numprocs; ++n)
- {
- if ( n == id )
- {
- printf(" %d: ", id );
- for( i = 0; i < size; ++i)
- {
- printf(" %d ", array[i]);
- }
- printf("\n");
- if( id == numprocs - 1)
- printf("\n");
- }
- MPI_Barrier(MPI_COMM_WORLD);
- }
- }
- int main(int argc, char *argv[])
- {
- int id, numproc;
- int i, root;
- int buf[10];
- int reducebuf[10] = {0};
- MPI_Init(&argc, &argv);
- MPI_Comm_rank(MPI_COMM_WORLD, &id);
- MPI_Comm_size(MPI_COMM_WORLD, &numproc);
- srand( id * time(NULL) );
- for( i = 0; i < 10; i++)
- {
- buf[i] = random()%10;
- }
- drukuj(id, numproc, buf, 10);
- if ( id == 0 )
- printf("\n");
- MPI_Barrier(MPI_COMM_WORLD);
- root = 0;
- MPI_Reduce( buf, reducebuf, 10, MPI_INT, MPI_MAX, root, MPI_COMM_WORLD);
- drukuj(id, numproc, reducebuf, 10);
- MPI_Finalize();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment