-
Notifications
You must be signed in to change notification settings - Fork 1
/
overlap_one_sided_put_dt.c
97 lines (76 loc) · 2.35 KB
/
overlap_one_sided_put_dt.c
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <mpi.h>
int main(void)
{
int i,me,np,n,provided,tmp,*blk_len,*disp,name_len;
double *x,*y,start_time,end_time,elapsed;
MPI_Win win;
MPI_Aint win_size;
MPI_Request req;
MPI_Status status;
MPI_Datatype dt;
char processor_name[MPI_MAX_PROCESSOR_NAME];
MPI_Init(NULL,NULL);
n = 100000;
MPI_Comm_rank(MPI_COMM_WORLD,&me);
MPI_Comm_size(MPI_COMM_WORLD,&np);
MPI_Get_processor_name(processor_name, &name_len);
if(me == 0 || me == np-1)
printf("Process %d has name %s\n",me,processor_name);
// Send/Recv to start communication
if(me == 0)
MPI_Send(&me,1,MPI_INT,np-1,0,MPI_COMM_WORLD);
if(me == np-1)
MPI_Recv(&tmp,1,MPI_INT,0,0,MPI_COMM_WORLD,&status);
//y = (double *)malloc(n*sizeof(double));
x = (double *)malloc(n*sizeof(double));
win_size = n * sizeof(double);
blk_len = (int *)calloc(100,sizeof(int));
disp = (int *)calloc(100,sizeof(int));
for(i=0;i<100;i++)
{
blk_len[i] = 1;
disp[i] = i+(9*i);
}
MPI_Type_indexed(100, blk_len, disp, MPI_DOUBLE, &dt);
MPI_Type_commit(&dt);
//MPI_Win_create(x, win_size, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &win);
MPI_Win_allocate(win_size, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &y, &win);
MPI_Barrier(MPI_COMM_WORLD);
for(i=0;i<n;i++)
x[i] = (double) i;
MPI_Barrier(MPI_COMM_WORLD);
if(me == 0)
{
start_time = MPI_Wtime();
MPI_Win_lock(MPI_LOCK_EXCLUSIVE, np-1, 0, win);
MPI_Put(x, 1, dt, np-1, 0, 1, dt, win);
MPI_Win_unlock(np-1,win);
end_time = MPI_Wtime();
printf("Process %d spent %lf seconds computing\n",me,end_time-start_time);
}
else if(me == np-1)
{
start_time = MPI_Wtime();
//Simulate computation for 2 seconds
usleep(2000000);
end_time = MPI_Wtime();
elapsed = end_time - start_time;
printf("Process %d spent %lf seconds getting the data\n",me,end_time-start_time);
printf("Value received y[10]=%lf. Expected %lf\n",y[10],10.0);
MPI_Send(&elapsed,1,MPI_DOUBLE,0,0,MPI_COMM_WORLD);
}
if(me == 0)
{
MPI_Recv(&elapsed,1,MPI_DOUBLE,np-1,0,MPI_COMM_WORLD,&status);
if(abs((end_time-start_time)-elapsed) < 0.5)
printf("NO OVERLAPPING\n");
else
printf("OVERLAPPING ACHIEVED\n");
}
MPI_Barrier(MPI_COMM_WORLD);
MPI_Finalize();
return 0;
}