1 #ifndef GA_UNIT_H
2 #define GA_UNIT_H
3 
4 #include "mp3.h"
5 
6 #define GA_PRINT_MSG() printf("Test Completed\n")
7 
8 #define GA_COMPLETE_MSG() printf("Test Completed\n")
9 
10 #define GA_ERROR_MSG() printf("GA ERROR\n")
11 
12 #define GA_ERROR_MSG2() printf("GA ERROR\n")
13 
14 /* the C long long type is rarely implemented for most GA operations */
15 #define TEST_LONGLONG 0
16 
17 #if TEST_LONGLONG
18 #   define NUM_TYPES 7
19 #else
20 #   define NUM_TYPES 6
21 #endif
22 int TYPES[NUM_TYPES] = {
23     C_INT,
24     C_LONG,
25 #if TEST_LONGLONG
26     C_LONGLONG,
27 #endif
28     C_FLOAT,
29     C_DBL,
30     C_SCPL,
31     C_DCPL,
32 };
33 
34 char* TYPE_NAMES[NUM_TYPES] = {
35     "C_INT",
36     "C_LONG",
37 #if TEST_LONGLONG
38     "C_LONGLONG",
39 #endif
40     "C_FLOAT",
41     "C_DBL",
42     "C_SCPL",
43     "C_DCPL",
44 };
45 
46 enum dist_type {
47     DIST_REGULAR=0,
48     DIST_CHUNK,
49     DIST_IRREGULAR,
50     DIST_BLOCK_CYCLIC,
51     DIST_SCALAPACK,
52     NUM_DISTS,
53 };
54 
55 int DIST_TYPES[NUM_DISTS] = {
56     DIST_REGULAR,
57     DIST_CHUNK,
58     DIST_IRREGULAR,
59     DIST_BLOCK_CYCLIC,
60     DIST_SCALAPACK,
61 };
62 
63 char* DIST_NAMES[NUM_DISTS] = {
64     "DIST_REGULAR",
65     "DIST_CHUNK",
66     "DIST_IRREGULAR",
67     "DIST_BLOCK_CYCLIC",
68     "DIST_SCALAPACK",
69 };
70 
71 #define NUM_SHAPES 4
72 static int SHAPES_ZERO[] = {10};
73 #define    SHAPES_ZERO_NDIM 1
74 #define    SHAPES_ZERO_NAME "10"
75 static int SHAPES_ONE[] = {2,3};
76 #define    SHAPES_ONE_NDIM 2
77 #define    SHAPES_ONE_NAME "2x3"
78 static int SHAPES_TWO[] = {2,3,4};
79 #define    SHAPES_TWO_NDIM 3
80 #define    SHAPES_TWO_NAME "2x3x4"
81 static int SHAPES_THREE[] = {2,3,4,5};
82 #define    SHAPES_THREE_NDIM 4
83 #define    SHAPES_THREE_NAME "2x3x4x5"
84 
85 static int* SHAPES[] = {
86     SHAPES_ZERO,
87     SHAPES_ONE,
88     SHAPES_TWO,
89     SHAPES_THREE,
90     NULL
91 };
92 static char* SHAPE_NAMES[] = {
93     SHAPES_ZERO_NAME,
94     SHAPES_ONE_NAME,
95     SHAPES_TWO_NAME,
96     SHAPES_THREE_NAME,
97     NULL
98 };
99 static int SHAPES_NDIM[] = {
100     SHAPES_ZERO_NDIM,
101     SHAPES_ONE_NDIM,
102     SHAPES_TWO_NDIM,
103     SHAPES_THREE_NDIM,
104 };
105 
106 //#define OP_TYPES 6
107 //char operators[OP_TYPES] = {'+', '*', 'max', 'min', 'absmax', 'absmin'};
108 
109 #define TEST_SETUP    GA_Initialize_args(&argc, &argv)
110 #define TEST_TEARDOWN GA_Terminate(); MP_FINALIZE()
111 
aprint(char * name,int * array,int size)112 static void aprint(char *name, int *array, int size)
113 {
114     int i;
115     printf("%s={", name);
116     if (size > 0) {
117         printf("%d", array[0]);
118     }
119     for (i=1; i<size; ++i) {
120         printf(",%d", array[i]);
121     }
122     printf("}\n");
123 }
124 
create_regular(int type,int ndim,int * shape)125 static int create_regular(int type, int ndim, int *shape) {
126     return NGA_Create(type, ndim, shape, "name", NULL);
127 }
128 
129 /* chunk is based on a random value between 0 and the dimension's limit */
create_chunk(int type,int ndim,int * shape)130 static int create_chunk(int type, int ndim, int *shape) {
131 #if 1
132     int i;
133     int chunk[GA_MAX_DIM];
134 
135     /* the chunks must be the same on each process! */
136     if (0 == GA_Nodeid()) {
137         for (i=0; i<ndim; ++i) {
138             chunk[i] = rand() % shape[i];
139         }
140     }
141     GA_Brdcst(chunk, ndim*sizeof(int), 0);
142     if (0 == GA_Nodeid()) {
143         printf("\tcreating chunked array\n");
144         printf("\t");
145         aprint("shape", shape, ndim);
146         printf("\t");
147         aprint("chunk", chunk, ndim);
148     }
149     return NGA_Create(type, ndim, shape, "name", chunk);
150 #else
151     return NGA_Create(type, ndim, shape, "name", NULL);
152 #endif
153 }
154 
create_irregular(int type,int ndim,int * shape)155 static int create_irregular(int type, int ndim, int *shape) {
156     return NGA_Create(type, ndim, shape, "name", NULL);
157 }
158 
create_block_cyclic(int type,int ndim,int * shape)159 static int create_block_cyclic(int type, int ndim, int *shape) {
160     return NGA_Create(type, ndim, shape, "name", NULL);
161 }
162 
create_scalapack(int type,int ndim,int * shape)163 static int create_scalapack(int type, int ndim, int *shape) {
164     return NGA_Create(type, ndim, shape, "name", NULL);
165 }
166 
167 typedef int(*creator)(int,int,int*);
168 
169 static creator create_function[] = {
170     create_regular,
171     create_chunk,
172     create_irregular,
173     create_block_cyclic,
174     create_scalapack,
175 };
176 
177 #endif
178