Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <mpi.h>
- #include <stdio.h>
- #include <stdlib.h>
- # define length 100
- int main(int argc, char** argv) {
- MPI_Init(&argc, &argv);
- int world_size;
- MPI_Comm_size(MPI_COMM_WORLD, &world_size);
- int rank;
- MPI_Comm_rank(MPI_COMM_WORLD, &rank);
- //MPI_Bcast(&x, 1, MPI_INT, 0, MPI_COMM_WORLD);
- float x = 0.0f;
- x = 1.0 / (3 + 4*rank);
- float sumMinus = 0.0f;
- MPI_Reduce(&x, &sumMinus, 1, MPI_FLOAT, MPI_SUM, 0, MPI_COMM_WORLD);
- //MPI_Bcast(&x, 1, MPI_INT, 0, MPI_COMM_WORLD);
- float y= 0.0f;
- y = 1.0 / (5 + 4*rank);
- float sumPlus = 0.0f;
- MPI_Reduce(&y, &sumPlus, 1, MPI_FLOAT, MPI_SUM, 0, MPI_COMM_WORLD);
- if( rank==0 ){
- printf( "sumMinus: %f, sumPlus: %f", sumMinus, sumPlus );
- float wynik = 1 -sumMinus + sumPlus;
- printf("\nPI/4 = %f", wynik);
- printf("\nPI = %f", wynik*4 );
- }
- MPI_Finalize();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement