1 /*
2  * Test Program for GA
3  * This is to test GA_Gather (is a one-sided operation)
4  * GA_Create -- used to create a global array using handles like 'g_A'
5  * GA_gather -- used to get data from different location
6  */
7 
8 #include<stdio.h>
9 #include<stdlib.h>
10 
11 #include"mpi.h"
12 #include"ga.h"
13 #include"macdecls.h"
14 #include"ga_unit.h"
15 
16 #define SIZE 10
17 #define N 5
18 #define D 2
19 
main(int argc,char ** argv)20 int main(int argc, char **argv)
21 {
22   int rank, nprocs;
23   int g_A, dims[D]={SIZE,SIZE}, *local_A=NULL, *local_G=NULL, **sub_array=NULL, **s_array=NULL;
24   int i, j, value=5;
25 
26   MPI_Init(&argc, &argv);
27   GA_Initialize();
28   MA_init(C_INT, 1000, 1000);
29 
30   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
31   MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
32 
33   s_array=(int**)malloc(N*sizeof(int*));
34   for(i=0; i<N; i++)
35     {
36       s_array[i]=(int*)malloc(D*sizeof(int));
37       for(j=0; j<D; j++) s_array[i][j]=rand()%10;
38     }
39 
40   sub_array=(int**)malloc(N*sizeof(int*));
41   for(i=0; i<N; i++)
42     {
43       sub_array[i]=(int*)malloc(D*sizeof(int));
44       for(j=0; j<D; j++) sub_array[i][j]=rand()%10;
45     }
46 
47   for(i=0; i<N; i++) local_A=(int*)malloc(N*sizeof(int));
48 
49   for(i=0; i<N; i++) local_G=(int*)malloc(N*sizeof(int));
50 
51   g_A=NGA_Create(C_INT, D, dims, "array_A", NULL);
52   GA_Fill(g_A, &value);
53   GA_Sync();
54 
55   NGA_Scatter(g_A, local_A, s_array, N);
56   NGA_Gather(g_A, local_G, s_array, N);
57   GA_Sync();
58   GA_Print(g_A);
59 
60   if(rank==0)
61     {
62       for(i=0; i<N; i++)
63 	if(local_G[i]!=local_A[i]) printf("GA Error: \n");
64     }
65   GA_Sync();
66   if(rank==0)
67     GA_PRINT_MSG();
68 
69   GA_Terminate();
70   MPI_Finalize();
71   return 0;
72 }
73 
74