Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <mpi.h>
- #include <stdio.h>
- #include <stdlib.h>
- // C:\Users\Dawid\source\repos\mpi_3\x64\Debug\
- //mpiexec -n 10 *.exe
- int main(int argc, char** argv) {
- MPI_Init(&argc, &argv);
- int data = 1;
- int world_size;
- MPI_Comm_size(MPI_COMM_WORLD, &world_size);
- int rank;
- MPI_Comm_rank(MPI_COMM_WORLD, &rank);
- //MPI_Barrier(MPI_COMM_WORLD);
- MPI_Bcast(&data, 1, MPI_INT, 0, MPI_COMM_WORLD);
- if( rank!= 0 )
- data *= rank;
- printf("\nprocess: #%d recv: %d", rank, data);
- int globalSum = 0;
- int localSum = (rank+1);
- //funkcja zbiera dane z procesów konunikatora do wybranego root'a
- MPI_Reduce(&localSum, &globalSum, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
- printf("proc %d globalSum: %d", rank, globalSum);
- if (rank == 0) {
- printf("reduced value: %d", globalSum);
- }
- MPI_Finalize();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement