Skip to content

Commit 8c7a597

Browse files
author
sbstndbs
committed
Add OMP/MPI run
-run shell to execute with 16 thread each process pinned to l3cache
1 parent c553d85 commit 8c7a597

File tree

2 files changed

+43
-13
lines changed

2 files changed

+43
-13
lines changed

hybride.c

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77

88
int main(int argc, char** argv){
99

10+
unsigned long long N = 1000000 ;
11+
unsigned long long M = 100000;
12+
1013
int world_rank;
1114
int world_size;
1215

1316
int namelen ;
14-
int iam = 0 ;
15-
int np = 1 ;
17+
int iam ;
18+
int np ;
1619
MPI_Init(&argc,&argv);
1720
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
1821
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
@@ -26,7 +29,10 @@ int main(int argc, char** argv){
2629
printf("Hello from thread %d out of %d from process %d out of %d on %s\n",
2730
iam, np, world_rank, world_size, processor_name);
2831

29-
32+
float * array = malloc(N * sizeof(float));
33+
for (unsigned long long i = 0 ; i < N ; i++){
34+
array[i]=0.0;
35+
}
3036

3137
float value = 0.0 ;
3238
float recieved = 0.0 ;
@@ -44,6 +50,9 @@ int main(int argc, char** argv){
4450
}
4551
// recieve values from every other processes
4652
// in a sync way
53+
54+
55+
4756
for (int i = 1 ; i < world_size ; i++){
4857
MPI_Recv(&recieved, 1 , MPI_FLOAT , i ,i , MPI_COMM_WORLD, MPI_STATUS_IGNORE) ;
4958
if (recieved == (float)i){
@@ -75,28 +84,47 @@ int main(int argc, char** argv){
7584
MPI_Isend(&value, 1 , MPI_FLOAT , i , i , MPI_COMM_WORLD, &request) ;
7685
}
7786

87+
88+
89+
90+
7891
// recieve values from every other processes
7992
for (int i = 1 ; i < world_size ; i++){
8093
MPI_Irecv(&recieved, 1 , MPI_FLOAT , i ,i , MPI_COMM_WORLD, &request) ;
8194
MPI_Wait(&request , &status) ;
82-
if (recieved == (float)i){
83-
printf("process %d correctly send back\n", i);
95+
if (recieved == (float)i*M){
96+
printf("process %d correctly send back %f\n", i, recieved);
8497
}
8598
else{
86-
printf("process %d badly send back %f (%f excepted) \n", i, recieved , (float)i);
99+
printf("process %d badly send back %f (%f excepted) \n", i, recieved , (float)i*M);
87100
}
88-
}
101+
}
102+
103+
for (unsigned long long j = 0 ; j < M ; j++){
104+
#pragma omp parallel for
105+
for (unsigned long long i = 0 ; i < N ; i++){
106+
array[i] += world_rank*1.0 ;
107+
}
108+
}
89109
}
90110
else if (world_rank < world_size){
91111

92112
MPI_Irecv(&value , 1 , MPI_FLOAT , 0 , world_rank , MPI_COMM_WORLD , &request ) ;
113+
MPI_Wait(&request , &status) ;
93114
int inc = 0 ;
94-
#pragma omp parallel for
95-
for (int i = 0 ; i < 1000 ; i++){
96-
inc += 1 ;
97-
}
98-
MPI_Wait(&request , &status) ;
99-
MPI_Isend(&value , 1 , MPI_FLOAT , 0 , world_rank , MPI_COMM_WORLD, &request ) ;
115+
116+
117+
118+
value = array[N-1];
119+
MPI_Isend(&value , 1 , MPI_FLOAT , 0 , world_rank , MPI_COMM_WORLD, &request ) ;
120+
121+
for (unsigned long long j = 0 ; j < M ; j++){
122+
#pragma omp parallel for
123+
for (unsigned long long i = 0 ; i < N ; i++){
124+
array[i] += world_rank*1.0 ;
125+
}
126+
}
127+
100128
}
101129

102130

run_with_omp.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export OMP_NUM_THREADS=16
2+
mpirun -np 2 --map-by l3cache:PE=8 --bind-to core ./hybride

0 commit comments

Comments
 (0)