-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_gather.c
115 lines (100 loc) · 2.46 KB
/
test_gather.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
////////////////////////////////////////////////////////////////////
// 2D ELM - Gareth O'Brien
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<time.h>
#include<mpi.h>
int my_rank, my_size;
MPI_Comm new_comm;
MPI_Status status;
const int TAG_SEND = 50;
const int ndims = 1;
MPI_Datatype fcol; // new datatype for the slice
MPI_Datatype scol; // new datatype for the slice
#define MAX_NB_OF_COMM 512
MPI_Request array_of_requests[MAX_NB_OF_COMM];
MPI_Status array_of_statuses[MAX_NB_OF_COMM];
////////////////////////////////////////////////////////////////////
// MAIN
main(int argc ,char *argv[])
{
int i,j,k;
int dims[1],period[1],reorder;
int rank,size;
double start, finish,t;
//////////////////////////////////////////////////////////////////
// Initialising MPI
MPI_Init(&argc,&argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
dims[0]=size;
period[0]=1;
reorder=1;
MPI_Cart_create(MPI_COMM_WORLD, 1, dims, period, reorder, &new_comm);
MPI_Comm_rank(new_comm, &my_rank);
MPI_Comm_size(new_comm, &my_size);
if( argc!=1)
{
printf(" Incorrect usage -- try again -- \n");
MPI_Finalize(); exit(0);
}
/*
#define No 100
int test_array[No];
for(i=0; i<No; i++)
{
test_array[i]=my_rank;
}
if(my_rank==2)
{
for(i=0; i<No; i++)
printf("%d %d\n",my_rank,test_array[i]);
}
int root=0;
MPI_Gather( test_array, 10, MPI_INT, test_array, 10, MPI_INT, root, new_comm);
MPI_Barrier(new_comm);
MPI_Bcast(test_array,No,MPI_INT,root,new_comm);
if(my_rank==0)
{
for(i=0; i<No; i++)
printf("%d %d\n",my_rank,test_array[i]);
}
MPI_Barrier(new_comm);
if(my_rank==2)
{
for(i=0; i<No; i++)
printf("%d %d\n",my_rank,test_array[i]);
}*/
#define No 50
#define Nn 3
int test_array[No][Nn];
for(i=0; i<No; i++)
{
for(j=0; j<Nn; j++)
{
test_array[i][j]=my_rank+j;
}
}
if(my_rank==2)
{
for(i=0; i<No; i++)
printf("%d: %d %d %d\n",my_rank,test_array[i][0],test_array[i][1],test_array[i][2]);
}
int root=0;
MPI_Gather( test_array, 15, MPI_INT, test_array, 15, MPI_INT, root, new_comm);
MPI_Barrier(new_comm);
MPI_Bcast(test_array,No*Nn,MPI_INT,root,new_comm);
if(my_rank==0)
{
for(i=0; i<No; i++)
printf("%d: %d %d %d\n",my_rank,test_array[i][0],test_array[i][1],test_array[i][2]);
}
MPI_Barrier(new_comm);
if(my_rank==2)
{
for(i=0; i<No; i++)
printf("%d: %d %d %d\n",my_rank,test_array[i][0],test_array[i][1],test_array[i][2]);
}
MPI_Finalize();
}