1 /*
2 * Test Program for GA
3 * This is to test GA_Create (is a collective operation)
4 * GA_Create -- used to create a global array using handles like 'g_A'
5 * Here used GA_Inquire to verify that g_A hanle returns the right values of created_array
6 */
7
8 #include<stdio.h>
9
10 #include"mpi.h"
11 #include"ga.h"
12 #include"macdecls.h"
13
14 #define GSIZE 5
15
one_dimension(int rank,int nprocs)16 one_dimension(int rank, int nprocs)
17 {
18 int g_V;
19 int ndim=1, dims=GSIZE;
20 int dims2, ndim2, type, value=5;
21
22 g_V = NGA_Create(C_INT, ndim, &dims, "array_V", NULL);
23
24 GA_Fill(g_V, &value);
25 GA_Print(g_V);
26 GA_Sync();
27
28 // NGA_Inquire(g_V, &type, &ndim2, dims2);
29 //printf(" %d -- %d,,\n", type, ndim2);
30
31 //for(i=0; i<DIM; i++)
32 //printf("%d: %d[ %d] ...* \n", rank, i, dims2[i]);
33 GA_Destroy(g_V);
34 }
35
two_dimension(int rank,int nprocs)36 two_dimension(int rank, int nprocs)
37 {
38 int g_A;
39 int ndim=2, dims[2]={GSIZE,GSIZE};
40 int dims2[ndim], ndim2, type, value=5, i;
41
42 g_A = NGA_Create(C_INT, ndim, dims, "array_A", NULL);
43
44 GA_Fill(g_A, &value);
45 GA_Print(g_A);
46 GA_Sync();
47
48 NGA_Inquire(g_A, &type, &ndim2, dims2);
49 printf(" %d -- %d,,\n", type, ndim2);
50
51 for(i=0; i<ndim; i++)
52 printf("%d: %d[ %d] ...* \n", rank, i, dims2[i]);
53 GA_Destroy(g_A);
54 }
55
three_dimension(int rank,int nprocs)56 three_dimension(int rank, int nprocs)
57 {
58 int g_A;
59 int ndim=3, dims[3]={GSIZE,GSIZE,GSIZE};
60 int dims2[ndim], ndim2, type, value=5, i;
61
62 g_A = NGA_Create(C_INT, ndim, dims, "array_A", NULL);
63
64 GA_Fill(g_A, &value);
65 GA_Print(g_A);
66 GA_Sync();
67
68 NGA_Inquire(g_A, &type, &ndim2, dims2);
69 printf(" %d -- %d,,\n", type, ndim2);
70
71 for(i=0; i<ndim; i++)
72 printf("%d: %d[ %d] ...* \n", rank, i, dims2[i]);
73 GA_Destroy(g_A);
74 }
75
fourth_dimension(int rank,int nprocs)76 fourth_dimension(int rank, int nprocs)
77 {
78 int g_A;
79 int ndim=4, dims[4]={GSIZE,GSIZE,GSIZE,GSIZE};
80 int dims2[ndim], ndim2, type, value=5, i;
81
82 g_A = NGA_Create(C_INT, ndim, dims, "array_A", NULL);
83
84 GA_Fill(g_A, &value);
85 GA_Print(g_A);
86 GA_Sync();
87
88 NGA_Inquire(g_A, &type, &ndim2, dims2);
89 printf(" %d -- %d,,\n", type, ndim2);
90
91 for(i=0; i<ndim; i++)
92 printf("%d: %d[ %d] ...* \n", rank, i, dims2[i]);
93 GA_Destroy(g_A);
94 }
95
main(int argc,char ** argv)96 int main(int argc, char **argv)
97 {
98 int rank, nprocs, i;
99
100 MPI_Init(&argc, &argv);
101
102 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
103 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
104
105 MA_init(C_INT, 1000, 1000);
106
107 GA_Initialize();
108
109 if(rank==1) printf(" ONE DIMENSION\n");
110 one_dimension(rank, nprocs);
111 GA_Sync();
112 if(rank==1) printf(" TWO DIMENSION\n");
113 two_dimension(rank, nprocs);
114 GA_Sync();
115 if(rank==1) printf(" THREE DIMENSION\n");
116 three_dimension(rank, nprocs);
117
118 // fourth_dimension(rank, nprocs);
119 GA_Sync();
120 if(rank == 0)
121 printf("Test Completed \n");
122 GA_Terminate();
123 MPI_Finalize();
124
125 }
126