16
#define N 4 /* dimension of matrices */
19
int main( int argc, char **argv ) {
21
int n=N, type=MT_F_DBL;
22
int dims[6]={N,N,N,N,N,N};
25
int heap=30000, stack=20000;
28
int datatype, elements;
33
GA_INIT(argc,argv); /* initialize GA */
37
if(GA_Uses_fapi())GA_Error("Program runs with C array API only",1);
38
printf("Using %ld processes\n",(long)nproc);
44
if(! MA_init(MT_F_DBL, stack, heap))
45
GA_Error("MA_init failed",stack+heap); /* initialize memory allocator*/
48
/* This is a regular matrix. */
49
if(me==0)printf("Creating matrix A\n");
50
g_a = NGA_Create(type, 2, dims, "A", NULL);
51
if(!g_a) GA_Error("create failed: A",n);
52
if(me==0)printf("OK\n");
53
NGA_Distribution( g_a, me, lo, hi );
56
/* This is just allocating and freeing memory. */
59
for ( i=0; i<2; i++ ) {
60
elements *= (hi[i] - lo[i] + 1);
62
prealloc_mem = GA_Getmem(datatype, elements, 0);
63
for ( i=0; i<elements; i++ ) prealloc_mem[i] = 3.141592654;
64
GA_Freemem(prealloc_mem);
65
if(me==0){printf("getmem&freemem OK\n"); fflush(stdout); }
68
/* This is a matrix using preallocated memory. */
71
for ( i=0; i<2; i++ ) {
72
elements *= (hi[i] - lo[i] + 1);
74
prealloc_mem = GA_Getmem(datatype, elements, 0);
75
g_b = GA_Assemble_duplicate(g_a, "Matrix B", (void*)prealloc_mem );
76
if(GA_Compare_distr(g_a,g_b)){
77
if(me==0){printf("GA_Assemble_duplicate failed\n"); fflush(stdout); }
79
if(me==0){printf("GA_Assemble_duplicate OK\n"); fflush(stdout); }
84
if(me==0)printf("\nSuccess\n");