-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloop_mpi.cpp
More file actions
30 lines (19 loc) · 769 Bytes
/
loop_mpi.cpp
File metadata and controls
30 lines (19 loc) · 769 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include<iostream>
#include<mpi.h>
int main(int argc , char **argv){
MPI::Init(argc, argv);
// get the number of process and the id of this process
int rank= MPI::COMM_WORLD.Get_rank();
int nproc =MPI::COMM_WORLD.Get_size(); // return the number of the process in the MPI team.
//we want to perfom 1000 iterations in total. Work out the number of iterations to perform per process..
int count = 1000/nproc;
// we use the rank of this process to work out which iterations to perform.
int start = rank*count;
int stop = start + count ;
// now perform the loop
int nloops = 0;
for(int i= start; i<stop; ++i){ ++nloops;}
std::cout<<" Process " << rank << " Performed " << nloops << " iterations of the loop. \n";
MPI::Finalize();
return 0;
}