1 /*
2 * Test Program for GA
3 * This is to test GA_Create_irreg (is a collective operation)
4 * GA_Create -- used to create a global array of regular size
5 * GA_Create_IRREG -- used to create G_array of irregular size -- helps user to define the distribution
6 * Here used GA_Inquire to verify that g_A hanle returns the right values of created_array
7 */
8
9 #include<stdio.h>
10 #include<stdlib.h>
11
12 #include"mpi.h"
13 #include"ga.h"
14 #include"macdecls.h"
15
16 #define DIM 2
17 #define GSIZE 10
18
irregular_array1(int rank)19 irregular_array1(int rank)
20 {
21
22 int g_A, g_B;
23 int dims[DIM]={5,10}, dims2[DIM], ndim, type, val_A=5, block[DIM]={2,3}, map[5]={0,2,0,4,6}, val_B=7;
24 int n_block[DIM], block_dims[DIM], i;
25
26 g_A = NGA_Create(C_INT, DIM, dims, "array_A", NULL);
27 g_B = NGA_Create_irreg(C_INT, DIM, dims, "array_B", block, map);
28
29 GA_Fill(g_A, &val_A);
30 GA_Print(g_A);
31
32 GA_Fill(g_B, &val_B);
33 GA_Print(g_B);
34 GA_Sync();
35
36 NGA_Inquire(g_A, &type, &ndim, dims2);
37 //printf(" %d -- %d,,\n", type, ndim);
38
39 /*
40 GA_Get_block_info(g_B, n_block, block_dims);
41 for(i=0; i<DIM; i++)
42 printf(" %d: %d ___ %d --- \n", rank, n_block[i], block_dims[i]);
43 */
44
45 GA_Destroy(g_A);
46 GA_Destroy(g_B);
47 }
48
irregular_array2(int rank)49 irregular_array2(int rank)
50 {
51
52 int g_A, g_B;
53 int dims[DIM]={GSIZE,GSIZE}, dims2[DIM], block[DIM]={3,2}, map[5]={0,2,6,0,4}, val_A=4, val_B=7;
54 int n_block[DIM], block_dims[DIM], i;
55
56 g_A = NGA_Create(C_INT, DIM, dims, "array_A", NULL);
57 g_B = NGA_Create_irreg(C_INT, DIM, dims, "array_B", block, map);
58
59
60 GA_Fill(g_A, &val_A);
61 GA_Print(g_A);
62
63 GA_Fill(g_B, &val_B);
64 GA_Print(g_B);
65 GA_Sync();
66
67 /*
68 GA_Get_block_info(g_B, n_block, block_dims);
69 for(i=0; i<DIM; i++)
70 printf(" %d: %d ___ %d --- \n", rank, n_block[i], block_dims[i]);
71 */
72
73 GA_Destroy(g_A);
74 GA_Destroy(g_B);
75 }
76
77 /* In these function the values of blocks and maps are auto-generated number based on number of processes we use */
78
auto_number1(int rank,int nprocs)79 auto_number1(int rank, int nprocs)
80 {
81
82 int g_A, g_B;
83 int dims[DIM]={GSIZE, GSIZE}, dims2[DIM], block[DIM], *map=NULL, val=7;
84 int n_block[DIM], block_dims[DIM], b_temp, i;
85 int b1, b2, inc=0;
86
87 do{
88 b1=DIM+inc;
89 b2=nprocs/b1;
90 inc++;
91 }while(nprocs/b1>=GSIZE);
92
93 block[0]=b1;
94 block[1]=b2;
95
96 map=(int*)malloc(nprocs*sizeof(int));
97
98 for(i=0; i<b1; i++)
99 map[i]=i*DIM;
100
101 for(i=b1; i<(b2+b1); i++)
102 map[i]=i-b1;
103
104 if(rank==0)
105 {
106 for(i=0; i<(b1+b2); i++)
107 printf("map[%d] - %d\n", i, map[i]);
108 for(i=0; i<DIM; i++)
109 printf("BLOCK[%d] - %d\n", i, block[i]);
110 }
111
112 g_B = NGA_Create_irreg(C_INT, DIM, dims, "array_B", block, map);
113
114 GA_Fill(g_B, &val);
115 GA_Print(g_B);
116 GA_Sync();
117
118 if(rank==1)
119 {
120 GA_Get_block_info(g_B, n_block, block_dims);
121 for(i=0; i<DIM; i++)
122 printf(" %d: %d --- %d ... %d\n", rank, n_block[i], block_dims[i], b_temp);
123 }
124 GA_Destroy(g_B);
125 }
126
auto_number2(int rank,int nprocs)127 auto_number2(int rank, int nprocs)
128 {
129
130 int g_A, g_B;
131 int dims[DIM]={GSIZE, GSIZE}, dims2[DIM], block[DIM], *map=NULL, val=7;
132 int n_block[DIM], block_dims[DIM], b_temp, i;
133 int b1, b2, inc=0;
134
135 do{
136
137 b2=DIM+inc;
138 b1=nprocs/b2;
139 inc++;
140 }while(nprocs/b2>=GSIZE);
141
142 block[0]=b1;
143 block[1]=b2;
144
145 map=(int*)malloc(nprocs*sizeof(int));
146
147 for(i=0; i<b1; i++)
148 map[i]=i;
149
150 for(i=b1; i<(b2+b1); i++)
151 map[i]=i-b1;
152
153 if(rank==0)
154 {
155 for(i=0; i<(b1+b2); i++)
156 printf("map[%d] - %d\n", i, map[i]);
157 for(i=0; i<DIM; i++)
158 printf("BLOCK[%d] - %d\n", i, block[i]);
159 }
160
161 g_B = NGA_Create_irreg(C_INT, DIM, dims, "array_B", block, map);
162
163 GA_Fill(g_B, &val);
164 GA_Print(g_B);
165 GA_Sync();
166
167 if(rank==1)
168 {
169 GA_Get_block_info(g_B, n_block, block_dims);
170 for(i=0; i<DIM; i++)
171 printf(" %d: %d --- %d ... %d\n", rank, n_block[i], block_dims[i], b_temp);
172 }
173 GA_Destroy(g_B);
174 }
175
main(int argc,char ** argv)176 int main(int argc, char **argv)
177 {
178 int rank, nprocs;
179
180 MPI_Init(&argc, &argv);
181
182 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
183 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
184
185 MA_init(C_INT, 1000, 1000);
186
187 GA_Initialize();
188
189 // irregular_array1(rank);
190 irregular_array2(rank);
191
192 // auto_number1(rank, nprocs);
193 auto_number2(rank, nprocs);
194
195 if(rank == 0)
196 printf("Test Completed \n");
197
198 GA_Terminate();
199 MPI_Finalize();
200
201 }
202