Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- export PATH=$PATH:/usr/lib64/mpi/gcc/openmpi/bin
- export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib64/psm2
- mpicc -o main main.c
- mpirun main
- export PATH=$PATH:/usr/lib64/mpi/gcc/openmpi/bin
- export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib64/psm2
- mpicc -o main main.c
- mpirun --mca pml ob1 --mca btl self,tcp main
- //===========linijka do polaczenia sie z komputerami
- for i in `seq 11 25`; do ssh 10.16.121.$i mkdir cokolwiek "echo ok"; done
- //==================================================
- */
- #include <iostream>
- #include <stdlib.h>
- #include <mpi.h>
- using namespace std;
- void safePrintArray(int rank, int nProc, int *array, int size){
- int i, n;
- for(n=0;n<nProc;n++){
- int id = n;
- if(id == rank){
- printf(" %d : ", id);
- for(i=0; i<size; i++)
- printf(" %d ", array[i]);
- printf("\n");
- }
- MPI_Barrier(MPI_COMM_WORLD);
- }
- }
- int main(int argc, char **argv)
- {
- int id;
- int size;
- int root;
- int buf[10];
- int reducebuf[10] = {0};
- int *sendbuf;
- int i;
- MPI_Init(&argc, &argv);
- MPI_Comm_rank(MPI_COMM_WORLD, &id);
- MPI_Comm_size(MPI_COMM_WORLD, &size);
- for(i=0; i<10; i++)
- buf[i] = i%(id+1);
- safePrintArray(id, size, buf, 10);
- if (id==0) printf("\n\n");
- fflush(stdout);
- MPI_Barrier(MPI_COMM_WORLD);
- root = 0;
- MPI_Reduce(buf, reducebuf, 10, MPI_INT, MPI_MAX, root, MPI_COMM_WORLD);
- //MPI_Allreduce(buf, reducebuf,) 10, MPI_INIT, MPI_MAX, MPI_COMM_WORLD);
- safePrintArray(id, size, reducebuf, 10);
- MPI_Finalize();
- return 0;
- }
- //LISTING 6================================================
- #include <stdio.h>
- #include <math.h>
- #include <mpi.h>
- #include <stdlib.h>
- int main(int argc, char **argv){
- int my_rank, p;
- int i,n;
- double my_pi, pi, h, sum, x;
- if(argc<2){
- printf("Poprawne użycie programu: program liczba_przedzialow calkowania\n");
- exit(1);
- }
- MPI_Init(&argc, &argv);
- MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
- MPI_Comm_size(MPI_COMM_WORLD, &p);
- if(my_rank == 0)
- n=atoi(argv[1]);
- MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD);
- h=1.0/(double)n;
- /*Całka metodą trapezów*/
- sum=0.0;
- for (i=my_rank; i<n; i+=p){
- x=h*((double)i+0.5);
- sum+=4.0/(1.0+x*x);
- }
- my_pi=h*sum;
- MPI_Reduce(&my_pi, &pi, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
- if(my_rank == 0)
- printf("pi=%.16f\n", pi);
- MPI_Finalize();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement