~ubuntu-branches/ubuntu/saucy/nwchem/saucy

« back to all changes in this revision

Viewing changes to src/tools/ga-4-3/armci/src/test-ibm.c

  • Committer: Package Import Robot
  • Author(s): Michael Banck, Michael Banck, Daniel Leidert
  • Date: 2012-02-09 20:02:41 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120209200241-jgk03qfsphal4ug2
Tags: 6.1-1
* New upstream release.

[ Michael Banck ]
* debian/patches/02_makefile_flags.patch: Updated.
* debian/patches/02_makefile_flags.patch: Use internal blas and lapack code.
* debian/patches/02_makefile_flags.patch: Define GCC4 for LINUX and LINUX64
  (Closes: #632611 and LP: #791308).
* debian/control (Build-Depends): Added openssh-client.
* debian/rules (USE_SCALAPACK, SCALAPACK): Removed variables (Closes:
  #654658).
* debian/rules (LIBDIR, USE_MPIF4, ARMCI_NETWORK): New variables.
* debian/TODO: New file.
* debian/control (Build-Depends): Removed libblas-dev, liblapack-dev and
  libscalapack-mpi-dev.
* debian/patches/04_show_testsuite_diff_output.patch: New patch, shows the
  diff output for failed tests.
* debian/patches/series: Adjusted.
* debian/testsuite: Optionally run all tests if "all" is passed as option.
* debian/rules: Run debian/testsuite with "all" if DEB_BUILD_OPTIONS
  contains "checkall".

[ Daniel Leidert ]
* debian/control: Used wrap-and-sort. Added Vcs-Svn and Vcs-Browser fields.
  (Priority): Moved to extra according to policy section 2.5.
  (Standards-Version): Bumped to 3.9.2.
  (Description): Fixed a typo.
* debian/watch: Added.
* debian/patches/03_hurd-i386_define_path_max.patch: Added.
  - Define MAX_PATH if not defines to fix FTBFS on hurd.
* debian/patches/series: Adjusted.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: test.c,v 1.43.6.6 2007-08-30 22:59:27 manoj Exp $ */
 
2
#include <stdio.h>
 
3
#include <stdlib.h>
 
4
#include <assert.h>
 
5
 
 
6
#ifdef WIN32
 
7
#  include <windows.h>
 
8
#  define sleep(x) Sleep(1000*(x))
 
9
#else
 
10
#  include <unistd.h>
 
11
#endif
 
12
 
 
13
/* ARMCI is impartial to message-passing libs - we handle them with MP macros */
 
14
#if defined(PVM)
 
15
#   include <pvm3.h>
 
16
#   ifdef CRAY
 
17
#     define MPGROUP         (char *)NULL
 
18
#     define MP_INIT(arc,argv)
 
19
#   else
 
20
#     define MPGROUP           "mp_working_group"
 
21
#     define MP_INIT(arc,argv) pvm_init(arc, argv)
 
22
#   endif
 
23
#   define MP_FINALIZE()     pvm_exit()
 
24
#   define MP_BARRIER()      pvm_barrier(MPGROUP,-1)
 
25
#   define MP_MYID(pid)      *(pid)   = pvm_getinst(MPGROUP,pvm_mytid())
 
26
#   define MP_PROCS(pproc)   *(pproc) = (int)pvm_gsize(MPGROUP)
 
27
    void pvm_init(int argc, char *argv[]);
 
28
#elif defined(TCGMSG)
 
29
#   include <sndrcv.h>
 
30
    long tcg_tag =30000;
 
31
#   define MP_BARRIER()      SYNCH_(&tcg_tag)
 
32
#   define MP_INIT(arc,argv) PBEGIN_((argc),(argv))
 
33
#   define MP_FINALIZE()     PEND_()
 
34
#   define MP_MYID(pid)      *(pid)   = (int)NODEID_()
 
35
#   define MP_PROCS(pproc)   *(pproc) = (int)NNODES_()
 
36
#elif defined(BGML)
 
37
# include "bgml.h"
 
38
# define MP_BARRIER()      bgml_barrier(3);
 
39
# define MP_FINALIZE()
 
40
# define MP_INIT(arc, argv)
 
41
# define MP_MYID(pid)      *(pid)=BGML_Messager_rank();
 
42
# define MP_PROCS(pproc)   *(pproc)=BGML_Messager_size();
 
43
#else
 
44
#   include <mpi.h>
 
45
#   define MP_BARRIER()      MPI_Barrier(MPI_COMM_WORLD)
 
46
#   define MP_FINALIZE()     MPI_Finalize()
 
47
#ifdef DCMF
 
48
#   define MP_INIT(arc,argv) \
 
49
    int desired = MPI_THREAD_MULTIPLE; \
 
50
    int provided; \
 
51
    printf("using MPI_Init_thread\n"); \
 
52
    MPI_Init_thread(&argc, &argv, desired, &provided); \
 
53
    if ( provided == MPI_THREAD_MULTIPLE ) printf("provided = MPI_THREAD_MULTIPLE\n"); \
 
54
    else if ( provided == MPI_THREAD_SERIALIZED ) printf("provided = MPI_THREAD_SERIALIZED\n"); \
 
55
    else if ( provided == MPI_THREAD_FUNNELED ) printf("provided = MPI_THREAD_FUNNELED\n"); \
 
56
    else if ( provided == MPI_THREAD_SINGLE ) printf("provided = MPI_THREAD_SINGLE\n");
 
57
#else
 
58
#   define MP_INIT(arc,argv) MPI_Init(&(argc),&(argv))
 
59
#endif
 
60
#   define MP_MYID(pid)      MPI_Comm_rank(MPI_COMM_WORLD, (pid))
 
61
#   define MP_PROCS(pproc)   MPI_Comm_size(MPI_COMM_WORLD, (pproc));
 
62
#endif
 
63
 
 
64
#include "armci.h"
 
65
 
 
66
#define DIM1 5
 
67
#define DIM2 3
 
68
#ifdef __sun
 
69
/* Solaris has shared memory shortages in the default system configuration */
 
70
# define DIM3 6
 
71
# define DIM4 5
 
72
# define DIM5 4
 
73
#elif defined(__alpha__)
 
74
# define DIM3 8
 
75
# define DIM4 5
 
76
# define DIM5 6
 
77
#else
 
78
# define DIM3 8
 
79
# define DIM4 9
 
80
# define DIM5 7
 
81
#endif
 
82
#define DIM6 3
 
83
#define DIM7 2
 
84
 
 
85
 
 
86
#define OFF 1
 
87
#define EDIM1 (DIM1+OFF)
 
88
#define EDIM2 (DIM2+OFF)
 
89
#define EDIM3 (DIM3+OFF)
 
90
#define EDIM4 (DIM4+OFF)
 
91
#define EDIM5 (DIM5+OFF)
 
92
#define EDIM6 (DIM6+OFF)
 
93
#define EDIM7 (DIM7+OFF)
 
94
 
 
95
#define DIMS 4
 
96
#define MAXDIMS 7
 
97
#define MAX_DIM_VAL 50 
 
98
#define LOOP 200
 
99
 
 
100
#define BASE 100.
 
101
#define MAXPROC 128
 
102
#define TIMES 100
 
103
 
 
104
#ifdef CRAY
 
105
# define ELEMS 800
 
106
#else
 
107
# define ELEMS 200
 
108
#endif
 
109
 
 
110
 
 
111
/***************************** macros ************************/
 
112
#define COPY(src, dst, bytes) memcpy((dst),(src),(bytes))
 
113
#define ARMCI_MAX(a,b) (((a) >= (b)) ? (a) : (b))
 
114
#define ARMCI_MIN(a,b) (((a) <= (b)) ? (a) : (b))
 
115
#define ARMCI_ABS(a) (((a) <0) ? -(a) : (a))
 
116
 
 
117
/***************************** global data *******************/
 
118
int me, nproc;
 
119
void* work[MAXPROC]; /* work array for propagating addresses */
 
120
 
 
121
 
 
122
 
 
123
#ifdef PVM
 
124
void pvm_init(int argc, char *argv[])
 
125
{
 
126
    int mytid, mygid, ctid[MAXPROC];
 
127
    int np, i;
 
128
 
 
129
    mytid = pvm_mytid();
 
130
    if((argc != 2) && (argc != 1)) goto usage;
 
131
    if(argc == 1) np = 1;
 
132
    if(argc == 2)
 
133
        if((np = atoi(argv[1])) < 1) goto usage;
 
134
    if(np > MAXPROC) goto usage;
 
135
 
 
136
    mygid = pvm_joingroup(MPGROUP);
 
137
 
 
138
    if(np > 1)
 
139
        if (mygid == 0) 
 
140
            i = pvm_spawn(argv[0], argv+1, 0, "", np-1, ctid);
 
141
 
 
142
    while(pvm_gsize(MPGROUP) < np) sleep(1);
 
143
 
 
144
    /* sync */
 
145
    pvm_barrier(MPGROUP, np);
 
146
    
 
147
    printf("PVM initialization done!\n");
 
148
    
 
149
    return;
 
150
 
 
151
usage:
 
152
    fprintf(stderr, "usage: %s <nproc>\n", argv[0]);
 
153
    pvm_exit();
 
154
    exit(-1);
 
155
}
 
156
#endif
 
157
 
 
158
/*\ generate random range for a section of multidimensional array 
 
159
\*/
 
160
void get_range(int ndim, int dims[], int lo[], int hi[]) 
 
161
{
 
162
        int dim;
 
163
        for(dim=0; dim <ndim;dim++){
 
164
                int toss1, toss2;
 
165
                toss1 = rand()%dims[dim];
 
166
                toss2 = rand()%dims[dim];
 
167
                if(toss1<toss2){
 
168
                        lo[dim]=toss1;
 
169
                        hi[dim]=toss2;
 
170
                }else {
 
171
                        hi[dim]=toss1;
 
172
                        lo[dim]=toss2;
 
173
                }
 
174
    }
 
175
}
 
176
 
 
177
 
 
178
 
 
179
/*\ generates a new random range similar to the input range for an array with specified dimensions
 
180
\*/
 
181
void new_range(int ndim, int dims[], int lo[], int hi[],int new_lo[], int new_hi[])
 
182
{
 
183
        int dim;
 
184
        for(dim=0; dim <ndim;dim++){
 
185
                int toss, range;
 
186
                int diff = hi[dim] -lo[dim]+1;
 
187
                assert(diff <= dims[dim]);
 
188
                range = dims[dim]-diff;
 
189
                toss = (range > 0)? rand()%range : lo[dim];
 
190
                new_lo[dim] = toss;
 
191
                new_hi[dim] = toss + diff -1;
 
192
                assert(new_hi[dim] < dims[dim]);
 
193
                assert(diff == (new_hi[dim] -new_lo[dim]+1));
 
194
        }
 
195
}
 
196
 
 
197
 
 
198
 
 
199
 
 
200
 
 
201
/*\ print range of ndim dimensional array with two strings before and after
 
202
\*/
 
203
void print_range(char *pre,int ndim, int lo[], int hi[], char* post)
 
204
{
 
205
        int i;
 
206
 
 
207
        printf("%s[",pre);
 
208
        for(i=0;i<ndim;i++){
 
209
                printf("%d:%d",lo[i],hi[i]);
 
210
                if(i==ndim-1)printf("] %s",post);
 
211
                else printf(",");
 
212
        }
 
213
}
 
214
 
 
215
/*\ print subscript of ndim dimensional array with two strings before and after
 
216
\*/
 
217
void print_subscript(char *pre,int ndim, int subscript[], char* post)
 
218
{
 
219
        int i;
 
220
 
 
221
        printf("%s [",pre);
 
222
        for(i=0;i<ndim;i++){
 
223
                printf("%d",subscript[i]);
 
224
                if(i==ndim-1)printf("] %s",post);
 
225
                else printf(",");
 
226
        }
 
227
}
 
228
 
 
229
 
 
230
/*\ print a section of a 2-D array of doubles
 
231
\*/
 
232
void print_2D_double(double *a, int ld, int *lo, int *hi)
 
233
{
 
234
int i,j;
 
235
     for(i=lo[0];i<=hi[0];i++){
 
236
       for(j=lo[1];j<=hi[1];j++) printf("%13f ",a[ld*j+i]);
 
237
       printf("\n");
 
238
     }
 
239
}
 
240
          
 
241
 
 
242
/*\ initialize array: a[i,j,k,..]=i+100*j+10000*k+ ... 
 
243
\*/
 
244
void init(double *a, int ndim, int elems, int dims[])
 
245
{
 
246
  int idx[MAXDIMS];
 
247
  int i,dim;
 
248
 
 
249
        for(i=0; i<elems; i++){
 
250
                int Index = i;
 
251
                double field, val;
 
252
        
 
253
                for(dim = 0; dim < ndim; dim++){
 
254
                        idx[dim] = Index%dims[dim];
 
255
                        Index /= dims[dim];
 
256
                }
 
257
                
 
258
        field=1.; val=0.;
 
259
                for(dim=0; dim< ndim;dim++){
 
260
                        val += field*idx[dim];
 
261
                        field *= BASE;
 
262
                }
 
263
                a[i] = val;
 
264
                /* printf("(%d,%d,%d)=%6.0f",idx[0],idx[1],idx[2],val); */
 
265
        }
 
266
}
 
267
 
 
268
 
 
269
/*\ compute Index from subscript
 
270
 *  assume that first subscript component changes first
 
271
\*/
 
272
int Index(int ndim, int subscript[], int dims[])
 
273
{
 
274
        int idx = 0, i, factor=1;
 
275
        for(i=0;i<ndim;i++){
 
276
                idx += subscript[i]*factor;
 
277
                factor *= dims[i];
 
278
        }
 
279
        return idx;
 
280
}
 
281
 
 
282
 
 
283
void update_subscript(int ndim, int subscript[], int lo[], int hi[], int dims[])
 
284
{
 
285
        int i;
 
286
        for(i=0;i<ndim;i++){
 
287
                if(subscript[i] < hi[i]) { subscript[i]++; return; }
 
288
                subscript[i] = lo[i];
 
289
        }
 
290
}
 
291
 
 
292
        
 
293
 
 
294
void compare_patches(double eps, int ndim, double *patch1, int lo1[], int hi1[],
 
295
                     int dims1[],double *patch2, int lo2[], int hi2[], 
 
296
                     int dims2[])
 
297
                                                   
 
298
{
 
299
        int i,j, elems=1;       
 
300
        int subscr1[MAXDIMS], subscr2[MAXDIMS];
 
301
        double diff,max;
 
302
 
 
303
        for(i=0;i<ndim;i++){   /* count # of elements & verify consistency of both patches */
 
304
                int diff = hi1[i]-lo1[i];
 
305
                assert(diff == (hi2[i]-lo2[i]));
 
306
                assert(diff < dims1[i]);
 
307
                assert(diff < dims2[i]);
 
308
                elems *= diff+1;
 
309
                subscr1[i]= lo1[i];
 
310
                subscr2[i]=lo2[i];
 
311
        }
 
312
 
 
313
        
 
314
        /* compare element values in both patches */ 
 
315
        for(j=0; j< elems; j++){ 
 
316
                int idx1, idx2, offset1, offset2;
 
317
                
 
318
                idx1 = Index(ndim, subscr1, dims1);      /* calculate element Index from a subscript */
 
319
                idx2 = Index(ndim, subscr2, dims2);
 
320
 
 
321
                if(j==0){
 
322
                        offset1 =idx1;
 
323
                        offset2 =idx2;
 
324
                }
 
325
                idx1 -= offset1;
 
326
                idx2 -= offset2;
 
327
                
 
328
 
 
329
                diff = patch1[idx1] - patch2[idx2];
 
330
                max  = ARMCI_MAX(ARMCI_ABS(patch1[idx1]),ARMCI_ABS(patch2[idx2]));
 
331
                if(max == 0. || max <eps) max = 1.; 
 
332
 
 
333
                if(eps < ARMCI_ABS(diff)/max){
 
334
                        char msg[48];
 
335
                        sprintf(msg,"(proc=%d):%f",me,patch1[idx1]);
 
336
                        print_subscript("ERROR: a",ndim,subscr1,msg);
 
337
                        sprintf(msg,"%f\n",patch2[idx2]);
 
338
                        print_subscript(" b",ndim,subscr2,msg);
 
339
                        fflush(stdout);
 
340
                        sleep(1);
 
341
                        ARMCI_Error("Bailing out",0);
 
342
                }
 
343
 
 
344
                { /* update subscript for the patches */
 
345
                   update_subscript(ndim, subscr1, lo1,hi1, dims1);
 
346
                   update_subscript(ndim, subscr2, lo2,hi2, dims2);
 
347
                }
 
348
        }
 
349
                                 
 
350
        
 
351
 
 
352
        /* make sure we reached upper limit */
 
353
        /*for(i=0;i<ndim;i++){ 
 
354
                assert(subscr1[i]==hi1[i]);
 
355
                assert(subscr2[i]==hi2[i]);
 
356
        }*/ 
 
357
}
 
358
 
 
359
 
 
360
void scale_patch(double alpha, int ndim, double *patch1, int lo1[], int hi1[], int dims1[])
 
361
{
 
362
        int i,j, elems=1;       
 
363
        int subscr1[MAXDIMS];
 
364
 
 
365
        for(i=0;i<ndim;i++){   /* count # of elements in patch */
 
366
                int diff = hi1[i]-lo1[i];
 
367
                assert(diff < dims1[i]);
 
368
                elems *= diff+1;
 
369
                subscr1[i]= lo1[i];
 
370
        }
 
371
 
 
372
        /* scale element values in both patches */ 
 
373
        for(j=0; j< elems; j++){ 
 
374
                int idx1, offset1;
 
375
                
 
376
                idx1 = Index(ndim, subscr1, dims1);      /* calculate element Index from a subscript */
 
377
 
 
378
                if(j==0){
 
379
                        offset1 =idx1;
 
380
                }
 
381
                idx1 -= offset1;
 
382
 
 
383
                patch1[idx1] *= alpha;
 
384
                update_subscript(ndim, subscr1, lo1,hi1, dims1);
 
385
        }       
 
386
}
 
387
 
 
388
#define MMAX 100
 
389
/* #define NEWMALLOC */
 
390
#ifdef NEWMALLOC
 
391
armci_meminfo_t meminfo[MMAX][MAXPROC];
 
392
int g_idx=0;
 
393
#endif
 
394
 
 
395
void create_array(void *a[], int elem_size, int ndim, int dims[])
 
396
{
 
397
     int bytes=elem_size, i, rc;
 
398
 
 
399
     assert(ndim<=MAXDIMS);
 
400
     for(i=0;i<ndim;i++)bytes*=dims[i];
 
401
#ifdef NEWMALLOC
 
402
     {
 
403
        if(g_idx>=100) ARMCI_Error("increase MMAX", g_idx);
 
404
        ARMCI_Memget(bytes, &meminfo[g_idx][me], 0);
 
405
 
 
406
        for(i=0; i<nproc; i++) 
 
407
           armci_msg_brdcst(&meminfo[g_idx][i], sizeof(armci_meminfo_t), i);
 
408
 
 
409
        for(i=0; i<nproc; i++) 
 
410
           a[i] = ARMCI_Memat(&meminfo[g_idx][i], 0);
 
411
        g_idx++;
 
412
     }
 
413
#else
 
414
     rc = ARMCI_Malloc(a, bytes);
 
415
     assert(rc==0);
 
416
#endif
 
417
     assert(a[me]);
 
418
     
 
419
}
 
420
 
 
421
void destroy_array(void *ptr[])
 
422
{
 
423
    MP_BARRIER();
 
424
#if 0
 
425
    assert(!ARMCI_Free(ptr[me]));
 
426
#endif
 
427
}
 
428
 
 
429
 
 
430
int loA[MAXDIMS], hiA[MAXDIMS];
 
431
int dimsA[MAXDIMS]={DIM1,DIM2,DIM3,DIM4,DIM5,DIM6, DIM7};
 
432
int loB[MAXDIMS], hiB[MAXDIMS];
 
433
int dimsB[MAXDIMS]={EDIM1,EDIM2,EDIM3,EDIM4,EDIM5,EDIM6,EDIM7};
 
434
int count[MAXDIMS];
 
435
int strideA[MAXDIMS], strideB[MAXDIMS];
 
436
int loC[MAXDIMS], hiC[MAXDIMS];
 
437
int idx[MAXDIMS]={0,0,0,0,0,0,0};
 
438
 
 
439
    
 
440
void test_dim(int ndim)
 
441
{
 
442
        int dim,elems;
 
443
        int i,j, proc;
 
444
        /* double a[DIM4][DIM3][DIM2][DIM1], b[EDIM4][EDIM3][EDIM2][EDIM1];*/
 
445
        void *b[MAXPROC];
 
446
        void *a, *c;
 
447
 
 
448
        elems = 1;   
 
449
        strideA[0]=sizeof(double); 
 
450
        strideB[0]=sizeof(double);
 
451
        for(i=0;i<ndim;i++){
 
452
                strideA[i] *= dimsA[i];
 
453
                strideB[i] *= dimsB[i];
 
454
                if(i<ndim-1){
 
455
                     strideA[i+1] = strideA[i];
 
456
                     strideB[i+1] = strideB[i];
 
457
                }
 
458
                elems *= dimsA[i];
 
459
        }
 
460
 
 
461
        /* create shared and local arrays */
 
462
        create_array(b, sizeof(double),ndim,dimsB);
 
463
        a = malloc(sizeof(double)*elems);
 
464
        assert(a);
 
465
        c = malloc(sizeof(double)*elems);
 
466
        assert(c);
 
467
 
 
468
        init(a, ndim, elems, dimsA);
 
469
        
 
470
        if(me==0){
 
471
            printf("--------array[%d",dimsA[0]);
 
472
            for(dim=1;dim<ndim;dim++)printf(",%d",dimsA[dim]);
 
473
            printf("]--------\n");
 
474
        }
 
475
        sleep(1);
 
476
 
 
477
        ARMCI_AllFence();
 
478
        MP_BARRIER();
 
479
        for(i=0;i<LOOP;i++){
 
480
            int idx1, idx2, idx3;
 
481
            get_range(ndim, dimsA, loA, hiA);
 
482
            new_range(ndim, dimsB, loA, hiA, loB, hiB);
 
483
            new_range(ndim, dimsA, loA, hiA, loC, hiC);
 
484
 
 
485
            proc=nproc-1-me;
 
486
 
 
487
            if(me==0){
 
488
               print_range("local",ndim,loA, hiA,"-> ");
 
489
               print_range("remote",ndim,loB, hiB,"-> ");
 
490
               print_range("local",ndim,loC, hiC,"\n");
 
491
            }
 
492
 
 
493
            idx1 = Index(ndim, loA, dimsA);
 
494
            idx2 = Index(ndim, loB, dimsB);
 
495
            idx3 = Index(ndim, loC, dimsA);
 
496
 
 
497
            for(j=0;j<ndim;j++)count[j]=hiA[j]-loA[j]+1;
 
498
 
 
499
            count[0]   *= sizeof(double); /* convert range to bytes at stride level zero */
 
500
 
 
501
            (void)ARMCI_PutS((double*)a + idx1, strideA, (double*)b[proc] + idx2, strideB, count, ndim-1, proc);
 
502
 
 
503
/*            sleep(1);*/
 
504
 
 
505
/*            printf("%d: a=(%x,%f) b=(%x,%f)\n",me,idx1 + (double*)a,*(idx1 + (double*)a),idx2 + (double*)b,*(idx2 + (double*)b));*/
 
506
/*            fflush(stdout);*/
 
507
/*            sleep(1);*/
 
508
 
 
509
            /* note that we do not need ARMCI_Fence here since
 
510
             * consectutive operations targeting the same process are ordered */
 
511
            (void)ARMCI_GetS((double*)b[proc] + idx2, strideB, (double*)c + idx3, strideA,  count, ndim-1, proc);
 
512
            
 
513
            compare_patches(0., ndim, (double*)a+idx1, loA, hiA, dimsA, (double*)c+idx3, loC, hiC, dimsA);
 
514
 
 
515
    
 
516
        }
 
517
 
 
518
        free(c);
 
519
        destroy_array(b);
 
520
        free(a);
 
521
}
 
522
 
 
523
int nloA[MAXDIMS+1][MAXDIMS], nhiA[MAXDIMS+1][MAXDIMS];
 
524
int nloB[MAXDIMS+1][MAXDIMS], nhiB[MAXDIMS+1][MAXDIMS];
 
525
int nloC[MAXDIMS+1][MAXDIMS], nhiC[MAXDIMS+1][MAXDIMS];
 
526
 
 
527
int get_next_RRproc(int initialize,int ndim){
 
528
static int distance;
 
529
int proc;
 
530
    if(initialize){
 
531
       distance=nproc/2;
 
532
       if((nproc%2)!=0)distance++;
 
533
       if(nproc==1)distance=0;
 
534
       return(0);
 
535
    }
 
536
    /*send it to a different process everytime*/
 
537
    proc=(me<=((nproc%2==0)?((nproc/2)-1):(nproc/2)))?(me+distance):(me-distance); 
 
538
    if((nproc%2)!=0 && me==(nproc/2))proc=me;
 
539
    if(distance!=0){
 
540
       if(me<(nproc/2)){
 
541
         distance++;
 
542
         if((me+distance)>=nproc){
 
543
           distance=nproc/2;
 
544
           if((nproc%2)!=0)distance++; 
 
545
           distance-=me;
 
546
         }
 
547
       }
 
548
       else {
 
549
         distance--;
 
550
         if((me-distance)>=(nproc/2)){
 
551
           distance=nproc/2;
 
552
           if((nproc%2)!=0)distance++; 
 
553
           distance=distance+(me-distance);
 
554
         }
 
555
       }    
 
556
       if(ndim!=1 && MAXDIMS>nproc && (ndim%(nproc/2)==0)){
 
557
         distance=nproc/2;
 
558
         if((nproc%2)!=0)distance++;
 
559
       }
 
560
    }
 
561
    return(proc);
 
562
}
 
563
 
 
564
void test_nbdim()
 
565
{
 
566
int elems=1,elems1=1;
 
567
int i,j, proc,ndim,rc;
 
568
void *b[MAXDIMS+1][MAXPROC];
 
569
void *a[MAXDIMS+1], *c[MAXDIMS+1];
 
570
armci_hdl_t hdl_put[MAXDIMS+1],hdl_get[MAXDIMS+1];
 
571
int idx1=0, idx2=0, idx3=0;
 
572
    /* create shared and local arrays */
 
573
    for(ndim=1;ndim<=MAXDIMS;ndim++){
 
574
       elems1*= dimsB[ndim-1];
 
575
       elems *= dimsA[ndim-1];
 
576
       rc = ARMCI_Malloc(b[ndim], sizeof(double)*elems1);
 
577
       assert(rc==0);assert(b[ndim][me]);
 
578
       a[ndim] = malloc(sizeof(double)*elems);
 
579
       assert(a[ndim]);
 
580
       c[ndim] = malloc(sizeof(double)*elems);
 
581
       assert(c[ndim]);
 
582
       init(a[ndim], ndim, elems, dimsA);
 
583
       ARMCI_INIT_HANDLE(hdl_put+ndim);
 
584
       ARMCI_INIT_HANDLE(hdl_get+ndim);
 
585
    }
 
586
    ARMCI_AllFence();
 
587
    MP_BARRIER();
 
588
 
 
589
    (void)get_next_RRproc(1,0);
 
590
    for(ndim=1;ndim<=MAXDIMS;ndim++){
 
591
       strideA[0]=sizeof(double);
 
592
       strideB[0]=sizeof(double);
 
593
       for(i=0;i<ndim;i++){
 
594
         strideA[i] *= dimsA[i];
 
595
         strideB[i] *= dimsB[i];
 
596
         if(i<ndim-1){
 
597
           strideA[i+1] = strideA[i];
 
598
           strideB[i+1] = strideB[i];
 
599
         }
 
600
       }
 
601
       proc=get_next_RRproc(0,ndim);
 
602
       get_range(ndim, dimsA, nloA[ndim], nhiA[ndim]);
 
603
       new_range(ndim, dimsB, nloA[ndim], nhiA[ndim], nloB[ndim], 
 
604
                 nhiB[ndim]);
 
605
       new_range(ndim, dimsA, nloA[ndim], nhiA[ndim], nloC[ndim], 
 
606
                 nhiC[ndim]);
 
607
       if(me==0){
 
608
         print_range("local",ndim,nloA[ndim], nhiA[ndim],"-> ");
 
609
         print_range("remote",ndim,nloB[ndim], nhiB[ndim],"-> ");
 
610
         print_range("local",ndim,nloC[ndim], nhiC[ndim],"\n");
 
611
         fflush(stdout); sleep(1);
 
612
       }
 
613
 
 
614
       idx1 = Index(ndim, nloA[ndim], dimsA);
 
615
       idx2 = Index(ndim, nloB[ndim], dimsB);
 
616
       idx3 = Index(ndim, nloC[ndim], dimsA);
 
617
       for(j=0;j<ndim;j++)count[j]=nhiA[ndim][j]-nloA[ndim][j]+1;
 
618
       count[0]   *= sizeof(double); 
 
619
 
 
620
       if(ndim==1){
 
621
         (void)ARMCI_NbPut((double*)a[ndim]+idx1,(double*)b[ndim][proc]+idx2,
 
622
                           count[0], proc, (hdl_put+ndim));
 
623
       }else{
 
624
         (void)ARMCI_NbPutS((double*)a[ndim]+idx1,strideA,
 
625
                          (double*)b[ndim][proc]+idx2,
 
626
                          strideB, count, ndim-1, proc,(hdl_put+ndim));
 
627
       }
 
628
    }
 
629
sleep(5);
 
630
    MP_BARRIER();
 
631
    /*before we do gets, we have to make sure puts are complete 
 
632
      on the remote processor*/
 
633
    for(ndim=1;ndim<=MAXDIMS;ndim++)
 
634
       ARMCI_Wait(hdl_put+ndim); 
 
635
    MP_BARRIER();
 
636
    ARMCI_AllFence();
 
637
 
 
638
    (void)get_next_RRproc(1,0);
 
639
    
 
640
    for(ndim=1;ndim<=MAXDIMS;ndim++){
 
641
       strideA[0]=sizeof(double);
 
642
       strideB[0]=sizeof(double);
 
643
       for(i=0;i<ndim;i++){
 
644
         strideA[i] *= dimsA[i];
 
645
         strideB[i] *= dimsB[i];
 
646
         if(i<ndim-1){
 
647
           strideA[i+1] = strideA[i];
 
648
           strideB[i+1] = strideB[i];
 
649
         }
 
650
       }
 
651
       /*send it to a different process everytime*/
 
652
       proc=get_next_RRproc(0,ndim);
 
653
 
 
654
       idx1 = Index(ndim, nloA[ndim], dimsA);
 
655
       idx2 = Index(ndim, nloB[ndim], dimsB);
 
656
       idx3 = Index(ndim, nloC[ndim], dimsA);
 
657
       for(j=0;j<ndim;j++)count[j]=nhiA[ndim][j]-nloA[ndim][j]+1;
 
658
       count[0]   *= sizeof(double); 
 
659
       if(ndim==1){
 
660
         (void)ARMCI_NbGet((double*)b[ndim][proc]+idx2,(double*)c[ndim]+idx3,
 
661
                           count[0], proc, (hdl_get+ndim));
 
662
       }else{
 
663
         (void)ARMCI_NbGetS((double*)b[ndim][proc]+idx2,strideB,
 
664
                          (double*)c[ndim]+idx3,
 
665
                          strideA, count, ndim-1, proc,(hdl_get+ndim));
 
666
       }
 
667
    }
 
668
       
 
669
    MP_BARRIER();
 
670
    if(me==0){
 
671
       printf("Now waiting for all non-blocking calls and verifying data...\n");
 
672
       fflush(stdout);
 
673
    }
 
674
    for(ndim=1;ndim<=MAXDIMS;ndim++){
 
675
       ARMCI_Wait(hdl_get+ndim); 
 
676
       idx1 = Index(ndim, nloA[ndim], dimsA);
 
677
       idx2 = Index(ndim, nloB[ndim], dimsB);
 
678
       idx3 = Index(ndim, nloC[ndim], dimsA);
 
679
       compare_patches(0.,ndim,(double*)a[ndim]+idx1,nloA[ndim],nhiA[ndim],
 
680
                     dimsA,(double*)c[ndim]+idx3,nloC[ndim],nhiC[ndim],dimsA);
 
681
    }
 
682
    if(me==0){
 
683
       printf("OK\n");
 
684
       fflush(stdout);
 
685
    }
 
686
    
 
687
    for(ndim=1;ndim<=MAXDIMS;ndim++){
 
688
       destroy_array(b[ndim]);
 
689
       free(c[ndim]);
 
690
       free(a[ndim]);
 
691
    }
 
692
}
 
693
 
 
694
#define PTR_ARR_LEN 10
 
695
#define VLOOP 50
 
696
#define VEC_ELE_LEN 20  /*number of doubles in each dimention*/
 
697
#define GIOV_ARR_LEN 9
 
698
 
 
699
void verify_vector_data(double *data,int procs,int isput,int datalen)
 
700
{
 
701
double facto=2.89;
 
702
int i,j=0,k=0,kc=0,dst=0;
 
703
    if(isput)facto=1.89;
 
704
    for(i=0;i<datalen;i++){
 
705
       if(dst!=me)
 
706
         if(ARMCI_ABS((data[i] -(me+facto+dst)*((kc+1)*(j%PTR_ARR_LEN + 1))))>0.001){
 
707
           printf("\n%d:while verifying data of a op from proc=%d ",me,dst);
 
708
           printf("giov index=%d ptr_arr_index=%d \n :element index=%d",kc,
 
709
                   (j%PTR_ARR_LEN),k);
 
710
           printf(" elem was supposed to be %f but is %f",
 
711
                  (me+facto+dst)*((kc+1)*(j%PTR_ARR_LEN + 1)) ,data[i]);
 
712
           fflush(stdout);
 
713
           sleep(1);
 
714
           ARMCI_Error("vector non-blocking failed",0);
 
715
         }  
 
716
       k++;
 
717
       if(k==VEC_ELE_LEN){
 
718
         j++;k=0;
 
719
         if(j%PTR_ARR_LEN==0){
 
720
           kc++;
 
721
           if((kc%GIOV_ARR_LEN)==0){kc=0;dst++;}
 
722
         }
 
723
       }
 
724
    }
 
725
}
 
726
 
 
727
void test_vec_small()
 
728
{
 
729
double *getdst;
 
730
double **putsrc;
 
731
armci_giov_t dsc[MAXPROC*GIOV_ARR_LEN];
 
732
void **psrc; /*arrays of pointers to be used by giov_t*/
 
733
void **pdst; 
 
734
void *getsrc[MAXPROC]; /*to allocate mem via armci_malloc*/
 
735
void *putdst[MAXPROC]; /*to allocate mem via armci_malloc*/
 
736
armci_hdl_t hdl_put[MAXPROC],hdl_get[MAXPROC];
 
737
int i=0,j=0,k=0,kc=0,kcold=0,rc,dstproc,dst=0;
 
738
int lenpergiov;
 
739
 
 
740
    lenpergiov = PTR_ARR_LEN*VEC_ELE_LEN;
 
741
    rc = ARMCI_Malloc(getsrc,sizeof(double)*nproc*GIOV_ARR_LEN*lenpergiov);
 
742
    assert(rc==0);assert(getsrc[me]);
 
743
    rc = ARMCI_Malloc(putdst,sizeof(double)*nproc*GIOV_ARR_LEN*lenpergiov);
 
744
    assert(rc==0);assert(putdst[me]);
 
745
 
 
746
    /*first malloc for getdst and putsrc, both are 2d arrays*/
 
747
    getdst = (double *)malloc(sizeof(double)*nproc*GIOV_ARR_LEN*lenpergiov);
 
748
    putsrc = (double **)malloc(sizeof(double *)*nproc*GIOV_ARR_LEN*PTR_ARR_LEN);
 
749
    assert(getdst);assert(putsrc);
 
750
    for(i=0;i<nproc*GIOV_ARR_LEN*PTR_ARR_LEN;i++){
 
751
       putsrc[i]=(double *)malloc(sizeof(double)*VEC_ELE_LEN);
 
752
       assert(putsrc[i]);
 
753
    }
 
754
    /*allocating memory for psrc and pdst*/
 
755
    psrc = (void **)malloc(sizeof(void *)*PTR_ARR_LEN * nproc*GIOV_ARR_LEN);
 
756
    pdst = (void **)malloc(sizeof(void *)*PTR_ARR_LEN * nproc*GIOV_ARR_LEN);
 
757
    assert(pdst);assert(psrc);
 
758
 
 
759
    for(i=0;i<nproc*lenpergiov*GIOV_ARR_LEN;i++){
 
760
       putsrc[j][k] =(me+1.89+dst)*((kc+1)*((j%PTR_ARR_LEN) + 1));
 
761
       ((double *)getsrc[me])[i]=(me+2.89+dst)*((kc+1)*(j%PTR_ARR_LEN + 1));
 
762
       k++;
 
763
       if(k==VEC_ELE_LEN){
 
764
         j++;k=0;
 
765
         if((j%PTR_ARR_LEN)==0){
 
766
           kc++;
 
767
           if((kc%GIOV_ARR_LEN)==0){kc=0;dst++;}
 
768
         }
 
769
       }
 
770
    }
 
771
    /*********************Testing NbPutV*********************************/
 
772
    i=0;j=0;k=0;kc=0; 
 
773
    dstproc = me;
 
774
    for(i=0;i<nproc-1;i++){
 
775
       dstproc++;if(dstproc==nproc)dstproc=0;
 
776
       for(j=0; j <GIOV_ARR_LEN; j++){
 
777
         kcold=kc;
 
778
         for(k=0;k<PTR_ARR_LEN;k++,kc++){
 
779
           double *ptr;
 
780
           psrc[kc]=(void *)putsrc[PTR_ARR_LEN*(dstproc*GIOV_ARR_LEN+j)+k];
 
781
           ptr = (double *)putdst[dstproc]; 
 
782
           pdst[kc]=(void *)(ptr+lenpergiov*(GIOV_ARR_LEN*me+j)+k*VEC_ELE_LEN);
 
783
         }
 
784
         dsc[j].bytes = VEC_ELE_LEN*sizeof(double);
 
785
         dsc[j].src_ptr_array = &psrc[kcold];
 
786
         dsc[j].dst_ptr_array = &pdst[kcold];
 
787
         dsc[j].ptr_array_len = PTR_ARR_LEN;
 
788
       }
 
789
       ARMCI_INIT_HANDLE(hdl_put+dstproc);
 
790
       if((rc=ARMCI_NbPutV(dsc,GIOV_ARR_LEN,dstproc,hdl_put+dstproc)))
 
791
         ARMCI_Error("putv failed",rc);
 
792
    }
 
793
    if(me==0){
 
794
       printf("\n\tNow veryfying the vector put data for correctness");
 
795
    }
 
796
    for(i=0;i<nproc;i++)if(i!=me)ARMCI_Wait(hdl_put+i);
 
797
    sleep(1);
 
798
    MP_BARRIER();
 
799
    ARMCI_AllFence();/*every one syncs after put */
 
800
    verify_vector_data((double *)putdst[me],nproc,1,nproc*GIOV_ARR_LEN*lenpergiov);
 
801
    if(me==0){
 
802
       printf("\n\tPuts OK\n");
 
803
    }
 
804
    /****************Done Testing NbPutV*********************************/
 
805
 
 
806
    /*********************Testing NbGetV*********************************/
 
807
    i=0;j=0;k=0;kc=0; 
 
808
    dstproc = me;
 
809
    for(i=0;i<nproc-1;i++){
 
810
       dstproc++;if(dstproc==nproc)dstproc=0;
 
811
       for(j=0; j <GIOV_ARR_LEN; j++){
 
812
         kcold=kc;
 
813
         for(k=0;k<PTR_ARR_LEN;k++,kc++){
 
814
           double *ptr;
 
815
           ptr = getdst;
 
816
           pdst[kc]=(void *)(ptr+lenpergiov*(dstproc*GIOV_ARR_LEN+j)+k*VEC_ELE_LEN);
 
817
           ptr = (double *)(getsrc[dstproc]); 
 
818
           psrc[kc]=(void *)(ptr+lenpergiov*(me*GIOV_ARR_LEN+j)+k*VEC_ELE_LEN);
 
819
         }
 
820
         dsc[j].bytes = VEC_ELE_LEN*sizeof(double);
 
821
         dsc[j].src_ptr_array = &psrc[kcold];
 
822
         dsc[j].dst_ptr_array = &pdst[kcold];
 
823
         dsc[j].ptr_array_len = PTR_ARR_LEN;
 
824
       }
 
825
       ARMCI_INIT_HANDLE(hdl_get+dstproc);
 
826
       if((rc=ARMCI_NbGetV(dsc,GIOV_ARR_LEN,dstproc,hdl_get+dstproc)))
 
827
         ARMCI_Error("putv failed",rc);
 
828
    }
 
829
    if(me==0){
 
830
       printf("\n\tNow veryfying the vector get data for correctness");
 
831
    }
 
832
    for(i=0;i<nproc;i++)if(i!=me)ARMCI_Wait(hdl_get+i);
 
833
    sleep(1);
 
834
    MP_BARRIER();
 
835
    verify_vector_data((double *)getdst,nproc,0,nproc*GIOV_ARR_LEN*lenpergiov);
 
836
    if(me==0){
 
837
       printf("\n\tGets OK\n");
 
838
    }
 
839
    /****************Done Testing NbGetV*********************************/
 
840
    free(pdst);
 
841
    free(psrc);
 
842
    free(getdst);
 
843
    for(i=0;i<nproc*GIOV_ARR_LEN*PTR_ARR_LEN;i++) free( putsrc[i]);
 
844
    free(putsrc);
 
845
}
 
846
 
 
847
 
 
848
 
 
849
void GetPermutedProcList(int* ProcList)
 
850
{
 
851
    int i, iswap, temp;
 
852
 
 
853
    if(nproc > MAXPROC) ARMCI_Error("permute_proc: nproc to big ", nproc);
 
854
 
 
855
    /* initialize list */
 
856
    for(i=0; i< nproc; i++) ProcList[i]=i;
 
857
    if(nproc ==1) return;
 
858
 
 
859
    /* every process generates different random sequence */
 
860
    (void)srand((unsigned)me);
 
861
 
 
862
    /* list permutation generated by random swapping */
 
863
    for(i=0; i< nproc; i++){
 
864
      iswap = (int)(rand() % nproc);
 
865
      temp = ProcList[iswap];
 
866
      ProcList[iswap] = ProcList[i];
 
867
      ProcList[i] = temp;
 
868
    }
 
869
}
 
870
 
 
871
 
 
872
 
 
873
/*\ Atomic Accumulate test:  remote += alpha*local
 
874
 *  Every process/or has its patch of array b updated TIMES*NPROC times.
 
875
 *  The sequence of updates is random: everybody uses a randomly permuted list
 
876
 *  and accumulate is non-collective (of-course)
 
877
\*/
 
878
void test_acc(int ndim)
 
879
{
 
880
        int dim,elems;
 
881
        int i, proc;
 
882
        void *b[MAXPROC];
 
883
        void *a, *c;
 
884
        double alpha=0.1, scale;
 
885
        int idx1, idx2;
 
886
        int *proclist = (int*)work;
 
887
 
 
888
        elems = 1;   
 
889
        strideA[0]=sizeof(double); 
 
890
        strideB[0]=sizeof(double);
 
891
        for(i=0;i<ndim;i++){
 
892
                strideA[i] *= dimsA[i];
 
893
                strideB[i] *= dimsB[i];
 
894
                if(i<ndim-1){
 
895
                     strideA[i+1] = strideA[i];
 
896
                     strideB[i+1] = strideB[i];
 
897
                }
 
898
                elems *= dimsA[i];
 
899
 
 
900
                /* set up patch coordinates: same on every processor */
 
901
                loA[i]=0;
 
902
                hiA[i]=loA[i]+1;
 
903
                loB[i]=dimsB[i]-2;
 
904
                hiB[i]=loB[i]+1;
 
905
                count[i]=hiA[i]-loA[i]+1;
 
906
        }
 
907
 
 
908
        /* create shared and local arrays */
 
909
        create_array(b, sizeof(double),ndim,dimsB);
 
910
        a = malloc(sizeof(double)*elems);
 
911
        assert(a);
 
912
        c = malloc(sizeof(double)*elems);
 
913
        assert(c);
 
914
 
 
915
        init(a, ndim, elems, dimsA);
 
916
        
 
917
        if(me==0){
 
918
            printf("--------array[%d",dimsA[0]);
 
919
            for(dim=1;dim<ndim;dim++)printf(",%d",dimsA[dim]);
 
920
            printf("]--------\n");
 
921
        }
 
922
 
 
923
        GetPermutedProcList(proclist);
 
924
 
 
925
        idx1 = Index(ndim, loA, dimsA);
 
926
        idx2 = Index(ndim, loB, dimsB);
 
927
        count[0]   *= sizeof(double); /* convert range to bytes at stride level zero */
 
928
        
 
929
        /* initialize all elements of array b to zero */
 
930
        elems = 1;
 
931
        for(i=0;i<ndim;i++)elems *= dimsB[i];
 
932
        for(i=0;i<elems;i++)((double*)b[me])[i]=0.;
 
933
 
 
934
        sleep(1);
 
935
 
 
936
        if(me==0){
 
937
               print_range("patch",ndim,loA, hiA," -> ");
 
938
               print_range("patch",ndim,loB, hiB,"\n");
 
939
               fflush(stdout);
 
940
        }
 
941
 
 
942
        ARMCI_AllFence();
 
943
        MP_BARRIER();
 
944
        for(i=0;i<TIMES*nproc;i++){ 
 
945
            proc=proclist[i%nproc];
 
946
            (void)ARMCI_AccS(ARMCI_ACC_DBL,&alpha,(double*)a + idx1, strideA, 
 
947
                   (double*)b[proc] + idx2, strideB, count, ndim-1, proc);
 
948
        }
 
949
 
 
950
/*      sleep(9);*/
 
951
        ARMCI_AllFence();
 
952
        MP_BARRIER();
 
953
 
 
954
        /* copy my patch into local array c */
 
955
        (void)ARMCI_GetS((double*)b[me] + idx2, strideB, (double*)c + idx1, strideA,  count, ndim-1, me);
 
956
 
 
957
        scale = alpha*TIMES*nproc; 
 
958
 
 
959
        scale_patch(scale, ndim, (double*)a+idx1, loA, hiA, dimsA);
 
960
        
 
961
        compare_patches(.0001, ndim, (double*)a+idx1, loA, hiA, dimsA, (double*)c+idx1, loA, hiA, dimsA);
 
962
        MP_BARRIER();
 
963
 
 
964
        if(0==me){
 
965
            printf(" OK\n\n");
 
966
            fflush(stdout);
 
967
        }
 
968
 
 
969
        free(c);
 
970
        destroy_array(b);
 
971
        free(a);
 
972
}
 
973
 
 
974
 
 
975
/*************************** vector interface *********************************\
 
976
 * tests vector interface for transfers of triangular sections of a 2-D array *
 
977
 ******************************************************************************/
 
978
void test_vector()
 
979
{
 
980
        int dim,elems,ndim,cols,rows,mrc;
 
981
        int i, proc, loop;
 
982
        int rc;
 
983
        int idx1, idx3;
 
984
        void *b[MAXPROC];
 
985
        void *a, *c;
 
986
        armci_giov_t dsc[MAX_DIM_VAL];
 
987
        void *psrc[MAX_DIM_VAL];
 
988
        void *pdst[MAX_DIM_VAL];
 
989
 
 
990
        elems = 1;   
 
991
        ndim  = 2;
 
992
        for(i=0;i<ndim;i++){
 
993
                dimsA[i]=MAX_DIM_VAL;
 
994
                dimsB[i]=MAX_DIM_VAL+1;
 
995
                elems *= dimsA[i];
 
996
        }
 
997
 
 
998
        /* create shared and local arrays */
 
999
        create_array(b, sizeof(double),ndim,dimsB);
 
1000
        a = malloc(sizeof(double)*elems);
 
1001
        assert(a);
 
1002
        c = malloc(sizeof(double)*elems);
 
1003
        assert(c);
 
1004
 
 
1005
        init(a, ndim, elems, dimsA);
 
1006
        
 
1007
        if(me==0){
 
1008
            printf("--------array[%d",dimsA[0]);
 
1009
            for(dim=1;dim<ndim;dim++)printf(",%d",dimsA[dim]);
 
1010
            printf("]--------\n");
 
1011
        }
 
1012
        sleep(1);
 
1013
 
 
1014
        for(loop=0;loop<LOOP;loop++){
 
1015
            get_range(ndim, dimsA, loA, hiA);
 
1016
            new_range(ndim, dimsB, loA, hiA, loB, hiB);
 
1017
            new_range(ndim, dimsA, loA, hiA, loC, hiC);
 
1018
 
 
1019
            proc=nproc-1-me;
 
1020
 
 
1021
            if(me==0){
 
1022
               print_range("local",ndim,loA, hiA,"-> ");
 
1023
               print_range("remote",ndim,loB, hiB,"-> ");
 
1024
               print_range("local",ndim,loC, hiC,"\n");
 
1025
            }
 
1026
 
 
1027
/*            printf("array at source\n");*/
 
1028
/*            print_2D_double((double *)a, dimsA[0], loA, hiA);*/
 
1029
 
 
1030
            cols =  hiA[1]-loA[1]+1; 
 
1031
            rows =  hiA[0]-loA[0]+1; 
 
1032
            mrc =ARMCI_MIN(cols,rows);
 
1033
 
 
1034
            /* generate a data descriptor for a lower-triangular patch */
 
1035
            for(i=0; i < mrc; i++){
 
1036
               int ij[2];
 
1037
               int idx;
 
1038
 
 
1039
               ij[0] = loA[0]+i;
 
1040
               ij[1] = loA[1]+i;
 
1041
               idx = Index(ndim, ij, dimsA);
 
1042
               psrc[i]= (double*)a + idx;
 
1043
 
 
1044
               ij[0] = loB[0]+i;
 
1045
               ij[1] = loB[1]+i;
 
1046
               idx = Index(ndim, ij, dimsB);
 
1047
               pdst[i]= (double*)b[proc] + idx;
 
1048
 
 
1049
               dsc[i].bytes = (rows-i)*sizeof(double);
 
1050
               dsc[i].src_ptr_array = &psrc[i];
 
1051
               dsc[i].dst_ptr_array = &pdst[i];
 
1052
 
 
1053
               /* assume each element different in size (not true in rectangular patches) */ 
 
1054
               dsc[i].ptr_array_len = 1; 
 
1055
            }
 
1056
 
 
1057
            if((rc=ARMCI_PutV(dsc, mrc, proc)))ARMCI_Error("putv failed ",rc);
 
1058
 
 
1059
/*            printf("array at destination\n");*/
 
1060
/*            print_2D_double((double *)b[proc], dimsB[0], loB, hiB);*/
 
1061
 
 
1062
            /* generate a data descriptor for the upper-triangular patch */
 
1063
            /* there is one less element since diagonal is excluded      */
 
1064
            for(i=1; i < cols; i++){
 
1065
               int ij[2];
 
1066
 
 
1067
               ij[0] = loA[0];
 
1068
               ij[1] = loA[1]+i;
 
1069
               psrc[i-1]= (double*)a + Index(ndim, ij, dimsA);
 
1070
 
 
1071
               ij[0] = loB[0];
 
1072
               ij[1] = loB[1]+i;
 
1073
               pdst[i-1]= (double*)b[proc] + Index(ndim, ij, dimsB);
 
1074
 
 
1075
               mrc = ARMCI_MIN(i,rows);
 
1076
               dsc[i-1].bytes = mrc*sizeof(double);
 
1077
               dsc[i-1].src_ptr_array = &psrc[i-1];
 
1078
               dsc[i-1].dst_ptr_array = &pdst[i-1];
 
1079
 
 
1080
               /* assume each element different in size (not true in rectangular patches) */ 
 
1081
               dsc[i-1].ptr_array_len = 1; 
 
1082
            }
 
1083
 
 
1084
            if((cols-1))if((rc=ARMCI_PutV(dsc, cols-1, proc)))
 
1085
                               ARMCI_Error("putv(2) failed ",rc);
 
1086
 
 
1087
            /* we get back entire rectangular patch */
 
1088
            for(i=0; i < cols; i++){
 
1089
               int ij[2];
 
1090
               ij[0] = loB[0];
 
1091
               ij[1] = loB[1]+i;
 
1092
               psrc[i]= (double*)b[proc] + Index(ndim, ij, dimsB);
 
1093
 
 
1094
               ij[0] = loC[0];
 
1095
               ij[1] = loC[1]+i;
 
1096
               pdst[i]= (double*)c + Index(ndim, ij, dimsA);
 
1097
            }
 
1098
 
 
1099
            dsc[0].bytes = rows*sizeof(double);
 
1100
            dsc[0].src_ptr_array = psrc;
 
1101
            dsc[0].dst_ptr_array = pdst;
 
1102
            dsc[0].ptr_array_len = cols; 
 
1103
 
 
1104
            /* note that we do not need ARMCI_Fence here since
 
1105
             * consecutive operations targeting the same process are ordered */
 
1106
            if((rc=ARMCI_GetV(dsc, 1, proc)))ARMCI_Error("getv failed ",rc);
 
1107
            
 
1108
            idx1 = Index(ndim, loA, dimsA);
 
1109
            idx3 = Index(ndim, loC, dimsA);
 
1110
            compare_patches(0., ndim, (double*)a+idx1, loA, hiA, dimsA, (double*)c+idx3, loC, hiC, dimsA);
 
1111
    
 
1112
        }
 
1113
 
 
1114
        free(c);
 
1115
        destroy_array(b);
 
1116
        free(a);
 
1117
}
 
1118
 
 
1119
 
 
1120
/*\ Atomic Accumulate test for vector API:  remote += alpha*local
 
1121
 *  Every process/or has its patch of array b updated TIMES*NPROC times.
 
1122
 *  The sequence of updates is random: everybody uses a randomly permuted list
 
1123
 *  and accumulate is non-collective (of-course)
 
1124
\*/
 
1125
void test_vector_acc()
 
1126
{
 
1127
        int dim,elems,bytes;
 
1128
        int i, j, proc, rc, one=1;
 
1129
        void *b[MAXPROC];
 
1130
        void *psrc[ELEMS/2], *pdst[ELEMS/2];
 
1131
        void *a, *c;
 
1132
        double alpha=0.1, scale;
 
1133
        int *proclist = (int*)work;
 
1134
        armci_giov_t dsc;
 
1135
 
 
1136
        elems = ELEMS;
 
1137
        dim =1;
 
1138
        bytes = sizeof(double)*elems;
 
1139
 
 
1140
        /* create shared and local arrays */
 
1141
        create_array(b, sizeof(double),dim,&elems);
 
1142
        a = malloc(bytes);
 
1143
        assert(a);
 
1144
        c = malloc(bytes);
 
1145
        assert(c);
 
1146
 
 
1147
        init(a, dim, elems, &elems);
 
1148
        
 
1149
        if(me==0){
 
1150
            printf("--------array[%d",elems);
 
1151
            printf("]--------\n");
 
1152
            fflush(stdout);
 
1153
        }
 
1154
 
 
1155
        GetPermutedProcList(proclist);
 
1156
        
 
1157
        /* initialize all elements of array b to zero */
 
1158
        for(i=0;i<elems;i++)((double*)b[me])[i]=0.;
 
1159
 
 
1160
        sleep(1);
 
1161
 
 
1162
        dsc.bytes = sizeof(double);
 
1163
        dsc.src_ptr_array = psrc;
 
1164
        dsc.dst_ptr_array = pdst;
 
1165
        dsc.ptr_array_len = elems/2; 
 
1166
 
 
1167
 
 
1168
        MP_BARRIER();
 
1169
        for(i=0;i<TIMES*nproc;i++){ 
 
1170
 
 
1171
/*            proc=proclist[i%nproc];*/
 
1172
            proc=0;
 
1173
 
 
1174
            /* accumulate even numbered elements */
 
1175
            for(j=0; j<elems/2; j++){
 
1176
                psrc[j]= 2*j + (double*)a;
 
1177
                pdst[j]= 2*j + (double*)b[proc];
 
1178
            }
 
1179
            if((rc = ARMCI_AccV(ARMCI_ACC_DBL, &alpha, &dsc, 1, proc)))
 
1180
                     ARMCI_Error("accumlate failed",rc);
 
1181
/*            for(j=0; j<elems; j++)
 
1182
                printf("%d %lf %lf\n",j, *(j+ (double*)b[proc]), *(j+ (double*)a));
 
1183
*/
 
1184
            /* accumulate odd numbered elements */
 
1185
            for(j=0; j< elems/2; j++){
 
1186
                psrc[j]= 2*j+1 + (double*)a;
 
1187
                pdst[j]= 2*j+1 + (double*)b[proc];
 
1188
            }
 
1189
            (void)ARMCI_AccV(ARMCI_ACC_DBL, &alpha, &dsc, 1, proc);
 
1190
 
 
1191
/*            for(j=0; j<elems; j++)
 
1192
                printf("%d %lf %lf\n",j, *(j+ (double*)a), *(j+ (double*)b[proc]));
 
1193
*/
 
1194
        }
 
1195
 
 
1196
        ARMCI_AllFence();
 
1197
        MP_BARRIER();
 
1198
 
 
1199
        /* copy my patch into local array c */
 
1200
        assert(!ARMCI_Get((double*)b[proc], c, bytes, proc));
 
1201
 
 
1202
/*        scale = alpha*TIMES*nproc; */
 
1203
        scale = alpha*TIMES*nproc*nproc; 
 
1204
        scale_patch(scale, dim, a, &one, &elems, &elems);
 
1205
        
 
1206
        compare_patches(.0001, dim, a, &one, &elems, &elems, c, &one, &elems, &elems);
 
1207
        MP_BARRIER();
 
1208
 
 
1209
        if(0==me){
 
1210
            printf(" OK\n\n");
 
1211
            fflush(stdout);
 
1212
        }
 
1213
 
 
1214
        free(c);
 
1215
        destroy_array((void**)b);
 
1216
        free(a);
 
1217
}
 
1218
 
 
1219
 
 
1220
 
 
1221
void test_fetch_add()
 
1222
{
 
1223
    int rc, bytes, i, val, times =0;
 
1224
    int *arr[MAXPROC];
 
1225
 
 
1226
    /* shared variable is located on processor 0 */
 
1227
    bytes = me == 0 ? sizeof(int) : 0;
 
1228
 
 
1229
    rc = ARMCI_Malloc((void**)arr,bytes);
 
1230
    assert(rc==0);
 
1231
    MP_BARRIER();
 
1232
 
 
1233
    if(me == 0) *arr[0] = 0;  /* initialization */
 
1234
 
 
1235
    MP_BARRIER();
 
1236
 
 
1237
    /* show what everybody gets */
 
1238
    rc = ARMCI_Rmw(ARMCI_FETCH_AND_ADD, &val, arr[0], 1, 0);
 
1239
    assert(rc==0);
 
1240
 
 
1241
    for(i = 0; i< nproc; i++){
 
1242
        if(i==me){
 
1243
            printf("process %d got value of %d\n",i,val);
 
1244
            fflush(stdout);
 
1245
        }
 
1246
        MP_BARRIER();
 
1247
    }
 
1248
 
 
1249
    if(me == 0){
 
1250
      printf("\nIncrement the shared counter until reaches %d\n",LOOP);
 
1251
      fflush(stdout);
 
1252
    }
 
1253
    
 
1254
    MP_BARRIER();
 
1255
 
 
1256
    /* now increment the counter value until reaches LOOP */
 
1257
    while(val<LOOP){
 
1258
          rc = ARMCI_Rmw(ARMCI_FETCH_AND_ADD, &val, arr[0], 1, 0);
 
1259
          assert(rc==0);
 
1260
          times++;
 
1261
    }
 
1262
 
 
1263
    for(i = 0; i< nproc; i++){
 
1264
        if(i==me){
 
1265
            printf("process %d incremented the counter %d times value=%d\n",i,times,val);
 
1266
            fflush(stdout);
 
1267
        }
 
1268
        MP_BARRIER();
 
1269
    }
 
1270
 
 
1271
 
 
1272
    if(me == 0) *arr[0] = 0;  /* set it back to 0 */
 
1273
    if(me == 0){
 
1274
       printf("\nNow everybody increments the counter %d times\n",LOOP); 
 
1275
       fflush(stdout);
 
1276
    }
 
1277
 
 
1278
    ARMCI_AllFence();
 
1279
    MP_BARRIER();
 
1280
 
 
1281
    for(i = 0; i< LOOP; i++){
 
1282
          rc = ARMCI_Rmw(ARMCI_FETCH_AND_ADD, &val, arr[0], 1, 0);
 
1283
          assert(rc==0);
 
1284
    }
 
1285
 
 
1286
    ARMCI_AllFence();
 
1287
    MP_BARRIER();
 
1288
 
 
1289
    if(me == 0){
 
1290
       printf("The final value is %d, should be %d.\n\n",*arr[0],LOOP*nproc); 
 
1291
       fflush(stdout);
 
1292
       if( *arr[0] != LOOP*nproc) ARMCI_Error("failed ...",*arr[0]);
 
1293
    }
 
1294
 
 
1295
    ARMCI_Free(arr[me]);
 
1296
}
 
1297
 
 
1298
 
 
1299
#define LOCKED -1
 
1300
void test_swap()
 
1301
{
 
1302
    int rc, bytes, i, val, whatever=-8999;
 
1303
    int *arr[MAXPROC];
 
1304
 
 
1305
    /* shared variable is located on processor 0 */
 
1306
    bytes = me == 0 ? sizeof(int) : 0;
 
1307
 
 
1308
    rc = ARMCI_Malloc((void**)arr,bytes);
 
1309
    assert(rc==0);
 
1310
    MP_BARRIER();
 
1311
 
 
1312
    if(me == 0) *arr[0] = 0;  /* initialization */
 
1313
 
 
1314
    ARMCI_AllFence();
 
1315
    MP_BARRIER();
 
1316
    for(i = 0; i< LOOP; i++){
 
1317
          val = LOCKED;
 
1318
          do{
 
1319
            rc = ARMCI_Rmw(ARMCI_SWAP, &val, arr[0], whatever, 0);
 
1320
            assert(rc==0);
 
1321
          }while (val == LOCKED); 
 
1322
          val++;
 
1323
          rc = ARMCI_Rmw(ARMCI_SWAP, &val, arr[0], whatever, 0);
 
1324
          assert(rc==0);
 
1325
    }
 
1326
 
 
1327
 
 
1328
    ARMCI_AllFence();
 
1329
    MP_BARRIER();
 
1330
 
 
1331
    if(me == 0){
 
1332
       printf("The final value is %d, should be %d.\n\n",*arr[0],LOOP*nproc); 
 
1333
       fflush(stdout);
 
1334
       if( *arr[0] != LOOP*nproc) ARMCI_Error("failed ...",*arr[0]);
 
1335
    }
 
1336
 
 
1337
    ARMCI_Free(arr[me]);
 
1338
}
 
1339
 
 
1340
 
 
1341
 
 
1342
 
 
1343
void test_memlock()
 
1344
{
 
1345
        int dim,elems,bytes;
 
1346
        int i, j,k, proc;
 
1347
        double *b[MAXPROC];
 
1348
        double *a, *c;
 
1349
#if 0
 
1350
        int *proclist = (int*)work;
 
1351
#endif
 
1352
                void *pstart, *pend;
 
1353
                int first, last;
 
1354
                void armci_lockmem(void*, void*, int);
 
1355
                void armci_unlockmem(void);
 
1356
 
 
1357
        elems = ELEMS;
 
1358
        dim =1;
 
1359
 
 
1360
                bytes = elems*sizeof(double);
 
1361
 
 
1362
        /* create shared and local arrays */
 
1363
        create_array((void**)b, sizeof(double),dim,&elems);
 
1364
        a = (double*)malloc(bytes);
 
1365
        assert(a);
 
1366
        c = (double*)malloc(bytes);
 
1367
        assert(c);
 
1368
        
 
1369
        /* initialize all elements of array b to zero */
 
1370
        for(i=0;i<elems;i++)b[me][i]=-1.;
 
1371
 
 
1372
        sleep(1);
 
1373
 
 
1374
        proc=0;
 
1375
                for(i=0;i<ELEMS/5;i++)a[i]=me;
 
1376
 
 
1377
        MP_BARRIER();
 
1378
        for(j=0;j<10*TIMES;j++){ 
 
1379
         for(i=0;i<TIMES*nproc;i++){ 
 
1380
            first = rand()%(ELEMS/2);
 
1381
                    last = first+ELEMS/5 -1;
 
1382
                        pstart = b[proc]+first;
 
1383
                        pend = b[proc]+last+1;
 
1384
                        elems = last -first +1;
 
1385
                        bytes = sizeof(double)*elems;
 
1386
 
 
1387
            armci_lockmem(pstart,pend,proc);
 
1388
            assert(!ARMCI_Put(a, pstart, bytes, proc));
 
1389
            assert(!ARMCI_Get(pstart, c, bytes, proc));
 
1390
            assert(!ARMCI_Get(pstart, c, bytes, proc));
 
1391
            armci_unlockmem();
 
1392
            for(k=0;k<elems;k++)if(a[k]!=c[k]){
 
1393
                printf("%d: error patch (%d:%d) elem=%d val=%f\n",me,first,last,k,c[k]);
 
1394
                fflush(stdout);
 
1395
                ARMCI_Error("failed is ",(int)c[k]);
 
1396
            }
 
1397
 
 
1398
          }
 
1399
          if(0==me)fprintf(stderr,"done %d\n",j);
 
1400
                }
 
1401
 
 
1402
        MP_BARRIER();
 
1403
 
 
1404
 
 
1405
        if(0==me){
 
1406
            printf(" OK\n\n");
 
1407
            fflush(stdout);
 
1408
        }
 
1409
 
 
1410
        free(c);
 
1411
        destroy_array((void**)b);
 
1412
        free(a);
 
1413
}
 
1414
 
 
1415
void test_rput()
 
1416
{
 
1417
    int i, elems = nproc, one=1;
 
1418
    int *idst[MAXPROC], idst_get[MAXPROC], *isrc_get[MAXPROC];
 
1419
    long *ldst[MAXPROC], ldst_get[MAXPROC], *lsrc_get[MAXPROC];
 
1420
    float *fdst[MAXPROC], fdst_get[MAXPROC], *fsrc_get[MAXPROC];
 
1421
    double *ddst[MAXPROC], ddst_get[MAXPROC], *dsrc_get[MAXPROC];
 
1422
 
 
1423
    create_array((void**)idst, sizeof(int),1, &elems);
 
1424
    create_array((void**)ldst, sizeof(long),1, &elems);
 
1425
    create_array((void**)fdst, sizeof(float),1, &elems);
 
1426
    create_array((void**)ddst, sizeof(double),1, &elems);     
 
1427
    create_array((void**)isrc_get, sizeof(int),1, &one);
 
1428
    create_array((void**)lsrc_get, sizeof(long),1, &one);
 
1429
    create_array((void**)fsrc_get, sizeof(float),1, &one);
 
1430
    create_array((void**)dsrc_get, sizeof(double),1, &one); 
 
1431
    
 
1432
    for(i=0; i<elems; i++) {
 
1433
      idst[me][i]=0; ldst[me][i]=0; fdst[me][i]=0.0; ddst[me][i]=0.0;
 
1434
      idst_get[i]=0; ldst_get[i]=0; fdst_get[i]=0.0; ddst_get[i]=0.0;      
 
1435
    }
 
1436
    isrc_get[me][0]=100*(me+1); lsrc_get[me][0]=100*(me+1);
 
1437
    fsrc_get[me][0]=100.01*(me+1); dsrc_get[me][0]=100.001*(me+1);
 
1438
 
 
1439
    
 
1440
    ARMCI_AllFence();
 
1441
    MP_BARRIER();
 
1442
    for(i=0; i<nproc; i++) {
 
1443
      ARMCI_PutValueInt(10*(me+1), (void *)&idst[i][me], i);
 
1444
      ARMCI_PutValueLong((long)10*(me+1), (void *)&ldst[i][me], i);
 
1445
      ARMCI_PutValueFloat(10.01*(me+1), (void *)&fdst[i][me], i);
 
1446
      ARMCI_PutValueDouble(10.001*(me+1), (void *)&ddst[i][me], i);
 
1447
    }
 
1448
 
 
1449
    for(i=0; i<nproc; i++) {
 
1450
      idst_get[i] = ARMCI_GetValueInt(isrc_get[i], i);
 
1451
      ldst_get[i] = ARMCI_GetValueLong(lsrc_get[i], i);
 
1452
      fdst_get[i] = ARMCI_GetValueFloat(fsrc_get[i], i);
 
1453
      ddst_get[i] = ARMCI_GetValueDouble(dsrc_get[i], i);
 
1454
    }
 
1455
    
 
1456
    ARMCI_AllFence();
 
1457
    MP_BARRIER();
 
1458
    
 
1459
    if(me==0)printf("int data type: ");
 
1460
    for(i=0; i<elems; i++) {
 
1461
      if(idst[me][i]!=10*(i+1))
 
1462
        ARMCI_Error("Integer register-originated put failed", 0);
 
1463
      if(idst_get[i]!=100*(i+1))
 
1464
        ARMCI_Error("Integer register-originated get failed", 0);
 
1465
    }
 
1466
    
 
1467
    if(me==0)printf("OK\nlong data type: ");
 
1468
    for(i=0; i<elems; i++) {
 
1469
      if(ldst[me][i]!=10*(i+1))
 
1470
        ARMCI_Error("Long register-originated put failed", 0);
 
1471
      if(ldst_get[i]!=100*(i+1))
 
1472
        ARMCI_Error("Long register-originated get failed", 0);
 
1473
    }
 
1474
    if(me==0)printf("OK\nfloat data type: ");
 
1475
    for(i=0; i<elems; i++) {
 
1476
      if( ARMCI_ABS(fdst[me][i]-10.01*(i+1)) > 0.1)
 
1477
        ARMCI_Error("Float register-originated put failed", 0);
 
1478
      if( ARMCI_ABS(fdst_get[i]-100.01*(i+1)) > 0.1)
 
1479
        ARMCI_Error("Float register-originated get failed", 0);
 
1480
    }
 
1481
    if(me==0)printf("OK\ndouble data type: ");
 
1482
    for(i=0; i<elems; i++) {
 
1483
      if(ARMCI_ABS(ddst[me][i]-10.001*(i+1)) > 0.1)
 
1484
        ARMCI_Error("Double register-originated put failed",0);
 
1485
      if(ARMCI_ABS(ddst_get[i]-100.001*(i+1)) > 0.1)
 
1486
        ARMCI_Error("Double register-originated get failed",0);
 
1487
    }
 
1488
    if(me==0){printf("OK\n"); fflush(stdout);}
 
1489
    
 
1490
    ARMCI_AllFence();
 
1491
    MP_BARRIER();
 
1492
    
 
1493
    
 
1494
    destroy_array((void **)idst);
 
1495
    destroy_array((void **)ldst);
 
1496
    destroy_array((void **)fdst);
 
1497
    destroy_array((void **)ddst);
 
1498
 
 
1499
    destroy_array((void **)isrc_get);
 
1500
    destroy_array((void **)lsrc_get);
 
1501
    destroy_array((void **)fsrc_get);
 
1502
    destroy_array((void **)dsrc_get);
 
1503
}
 
1504
 
 
1505
 
 
1506
#define MAXELEMS      6400
 
1507
#define NUMAGG        20   /* NUMAGG < MAXELEMS/10 */
 
1508
#define MAX_REQUESTS  325 /* MAXELEMS/NUMAGG */
 
1509
#define COUNT         50
 
1510
 
 
1511
void test_aggregate() {
 
1512
  
 
1513
    int i, j, k, rc, bytes, elems[2] = {MAXPROC, MAXELEMS};
 
1514
    double *ddst_put[MAXPROC];
 
1515
    double *ddst_get[MAXPROC];
 
1516
    double *dsrc[MAXPROC];
 
1517
    armci_hdl_t usr_hdl_put[MAXPROC];
 
1518
    armci_hdl_t usr_hdl_get[MAXPROC];
 
1519
    armci_giov_t darr;
 
1520
    void *src_ptr[MAX_REQUESTS], *dst_ptr[MAX_REQUESTS];
 
1521
    int start = 0, end = 0;
 
1522
        
 
1523
    create_array((void**)ddst_put, sizeof(double),2, elems);
 
1524
    create_array((void**)ddst_get, sizeof(double),2, elems);
 
1525
    create_array((void**)dsrc, sizeof(double),1, &elems[1]);
 
1526
    
 
1527
    for(i=0; i<elems[1]; i++) dsrc[me][i]=i*1.001*(me+1);
 
1528
    for(i=0; i<elems[0]*elems[1]; i++) {
 
1529
      ddst_put[me][i]=0.0;
 
1530
      ddst_get[me][i]=0.0;
 
1531
    }
 
1532
    
 
1533
    ARMCI_Barrier();
 
1534
    for(i=0; i<nproc; i++) ARMCI_INIT_HANDLE(&usr_hdl_put[i]);
 
1535
    for(i=0; i<nproc; i++) ARMCI_INIT_HANDLE(&usr_hdl_get[i]);
 
1536
    for(i=0; i<nproc; i++) ARMCI_SET_AGGREGATE_HANDLE(&usr_hdl_put[i]);
 
1537
    for(i=0; i<nproc; i++) ARMCI_SET_AGGREGATE_HANDLE(&usr_hdl_get[i]);    
 
1538
 
 
1539
    /* Testing aggregate put */
 
1540
    for(i=0; i<nproc; i++) {
 
1541
 
 
1542
      start = 0; end = COUNT*NUMAGG; 
 
1543
      for(j=start; j<end; j++) {  
 
1544
        bytes = sizeof(double);
 
1545
        ARMCI_NbPutValueDouble(dsrc[me][j], &ddst_put[i][me*elems[1]+j], i, 
 
1546
                               &usr_hdl_put[i]);
 
1547
      }
 
1548
      
 
1549
      start = end; end = start + COUNT*NUMAGG;
 
1550
      for(j=start, k=0; j<end; j+=NUMAGG, k++) {
 
1551
        src_ptr[k] = (void *)&dsrc[me][j];
 
1552
        dst_ptr[k] = (void *)&ddst_put[i][me*elems[1]+j];
 
1553
      }
 
1554
      darr.src_ptr_array = src_ptr;
 
1555
      darr.dst_ptr_array = dst_ptr;
 
1556
      darr.bytes = NUMAGG*sizeof(double);
 
1557
      darr.ptr_array_len = k;
 
1558
      if((rc=ARMCI_NbPutV(&darr, 1, i, &usr_hdl_put[i])))
 
1559
        ARMCI_Error("armci_nbputv failed\n",rc);
 
1560
 
 
1561
      start = end; end = start + COUNT*NUMAGG;
 
1562
      for(j=start; j<end; j+=NUMAGG) {  
 
1563
        bytes = sizeof(double)*NUMAGG;
 
1564
        if((rc=ARMCI_NbPutS(&dsrc[me][j], NULL, &ddst_put[i][me*elems[1]+j], NULL, 
 
1565
                            &bytes, 0, i, &usr_hdl_put[i])))
 
1566
          ARMCI_Error("armci_nbputs failed\n",rc);
 
1567
      }
 
1568
 
 
1569
      start = end; end = elems[1]; 
 
1570
      for(j=start; j<end; j+=NUMAGG) {  
 
1571
        bytes = sizeof(double)*NUMAGG;
 
1572
        if((rc=ARMCI_NbPut(&dsrc[me][j], &ddst_put[i][me*elems[1]+j], bytes,
 
1573
                           i, &usr_hdl_put[i])))
 
1574
          ARMCI_Error("armci_nbput failed\n",rc);
 
1575
      }
 
1576
 
 
1577
    }
 
1578
    
 
1579
    for(i=0; i<nproc; i++) ARMCI_Wait(&usr_hdl_put[i]);
 
1580
 
 
1581
    /* Testing aggregate get */
 
1582
    for(i=0; i<nproc; i++) {
 
1583
      
 
1584
      start = 0; end = COUNT*NUMAGG; 
 
1585
      for(j=start, k=0; j<end; j+=NUMAGG, k++) {
 
1586
        src_ptr[k] = (void *)&dsrc[i][j];
 
1587
        dst_ptr[k] = (void *)&ddst_get[me][i*elems[1]+j];
 
1588
      }
 
1589
      darr.src_ptr_array = src_ptr;
 
1590
      darr.dst_ptr_array = dst_ptr;
 
1591
      darr.bytes = NUMAGG*sizeof(double);
 
1592
      darr.ptr_array_len = k;
 
1593
      if((rc=ARMCI_NbGetV(&darr, 1, i, &usr_hdl_get[i])))
 
1594
        ARMCI_Error("armci_nbgetv failed\n", rc);
 
1595
 
 
1596
      start = end; end = start + COUNT*NUMAGG;
 
1597
      for(j=start; j<end; j+=NUMAGG) {  
 
1598
        bytes = sizeof(double)*NUMAGG;
 
1599
        if((rc=ARMCI_NbGetS(&dsrc[i][j], NULL, &ddst_get[me][i*elems[1]+j], NULL, 
 
1600
                            &bytes, 0, i, &usr_hdl_get[i])))
 
1601
          ARMCI_Error("armci_nbputs failed\n",rc);
 
1602
      }
 
1603
 
 
1604
      start = end; end = elems[1];
 
1605
      for(j=start; j<end; j+=NUMAGG) {  
 
1606
        bytes = sizeof(double)*NUMAGG;
 
1607
        if((rc=ARMCI_NbGet(&dsrc[i][j], &ddst_get[me][i*elems[1]+j], bytes,
 
1608
                           i, &usr_hdl_get[i])))
 
1609
          ARMCI_Error("armci_nbget failed\n",rc);
 
1610
      }
 
1611
    }
 
1612
 
 
1613
    for(i=0; i<nproc; i++) ARMCI_Wait(&usr_hdl_get[i]);
 
1614
        
 
1615
    
 
1616
    MP_BARRIER();
 
1617
    ARMCI_AllFence();
 
1618
    MP_BARRIER();
 
1619
    
 
1620
    for(i=0; i<nproc; i++) {
 
1621
      for(j=0; j<elems[1]; j++) {
 
1622
        if( ARMCI_ABS(ddst_put[me][i*elems[1]+j]-j*1.001*(i+1)) > 0.1) {
 
1623
          ARMCI_Error("aggregate put failed...1", 0);
 
1624
        }
 
1625
      }
 
1626
    }
 
1627
    MP_BARRIER();
 
1628
    if(me==0) printf("  aggregate put ..O.K.\n"); fflush(stdout);
 
1629
 
 
1630
    for(i=0; i<nproc; i++) {
 
1631
      for(j=0; j<elems[1]; j++) {
 
1632
        if( ARMCI_ABS(ddst_get[me][i*elems[1]+j]-j*1.001*(i+1)) > 0.1) {
 
1633
          ARMCI_Error("aggregate get failed...1", 0);
 
1634
        }
 
1635
      }
 
1636
    }
 
1637
    MP_BARRIER();
 
1638
    if(me==0) printf("  aggregate get ..O.K.\n"); fflush(stdout);
 
1639
    
 
1640
    ARMCI_AllFence();
 
1641
    MP_BARRIER();
 
1642
    
 
1643
    if(me==0){printf("O.K.\n"); fflush(stdout);}
 
1644
    destroy_array((void **)ddst_put);
 
1645
    destroy_array((void **)ddst_get);
 
1646
    destroy_array((void **)dsrc);
 
1647
}
 
1648
 
 
1649
void test_implicit() {
 
1650
  
 
1651
    int i, j, k, rc, bytes, elems[2] = {MAXPROC, MAXELEMS};
 
1652
    double *ddst_put[MAXPROC];
 
1653
    double *ddst_get[MAXPROC];
 
1654
    double *dsrc[MAXPROC];
 
1655
    armci_giov_t darr;
 
1656
    void *src_ptr[MAX_REQUESTS], *dst_ptr[MAX_REQUESTS];
 
1657
    int start = 0, end = 0;
 
1658
    armci_hdl_t usr_hdl[MAXPROC];
 
1659
    
 
1660
    create_array((void**)ddst_put, sizeof(double),2, elems);
 
1661
    create_array((void**)ddst_get, sizeof(double),2, elems);
 
1662
    create_array((void**)dsrc, sizeof(double),1, &elems[1]);
 
1663
    
 
1664
    for(i=0; i<elems[1]; i++) 
 
1665
      dsrc[me][i]=i*1.001*(me+1);
 
1666
    for(i=0; i<elems[0]*elems[1]; i++) 
 
1667
    {
 
1668
      ddst_put[me][i]=0.0;
 
1669
      ddst_get[me][i]=0.0;
 
1670
    }
 
1671
    
 
1672
    MP_BARRIER();
 
1673
    for(i=0; i<nproc; i++) ARMCI_INIT_HANDLE(&usr_hdl[i]);
 
1674
 
 
1675
    for(i=0; i<nproc; i++) 
 
1676
    {
 
1677
      
 
1678
      start = 0; end = COUNT*NUMAGG; 
 
1679
      for(j=start; j<end; j++) 
 
1680
      {  
 
1681
        bytes = sizeof(double);
 
1682
                ARMCI_NbPutValueDouble(dsrc[me][j], &ddst_put[i][me*elems[1]+j], i, 
 
1683
                               NULL);
 
1684
      }
 
1685
      
 
1686
      start = end; end = start + COUNT*NUMAGG;
 
1687
      for(j=start, k=0; j<end; j+=NUMAGG, k++) 
 
1688
      {
 
1689
        src_ptr[k] = (void *)&dsrc[me][j];
 
1690
        dst_ptr[k] = (void *)&ddst_put[i][me*elems[1]+j];
 
1691
      }
 
1692
      darr.src_ptr_array = src_ptr;
 
1693
      darr.dst_ptr_array = dst_ptr;
 
1694
      darr.bytes = NUMAGG*sizeof(double);
 
1695
      darr.ptr_array_len = k;
 
1696
      if((rc=ARMCI_NbPutV(&darr, 1, i, NULL)))
 
1697
                ARMCI_Error("armci_nbputv failed\n",rc);
 
1698
 
 
1699
      start = end; end = start + COUNT*NUMAGG;
 
1700
      for(j=start; j<end; j+=NUMAGG) 
 
1701
      {  
 
1702
        bytes = sizeof(double)*NUMAGG;
 
1703
        if((rc=ARMCI_NbPutS(&dsrc[me][j], NULL, &ddst_put[i][me*elems[1]+j], NULL, 
 
1704
                            &bytes, 0, i, NULL)))
 
1705
          ARMCI_Error("armci_nbputs failed\n",rc);
 
1706
      }
 
1707
 
 
1708
      start = end; end = elems[1]; 
 
1709
      for(j=start; j<end; j+=NUMAGG) 
 
1710
      {  
 
1711
        bytes = sizeof(double)*NUMAGG;
 
1712
        if((rc=ARMCI_NbPut(&dsrc[me][j], &ddst_put[i][me*elems[1]+j], bytes,
 
1713
                           i, NULL)))
 
1714
          ARMCI_Error("armci_nbput failed\n",rc);
 
1715
      }
 
1716
    }
 
1717
 
 
1718
 
 
1719
    for(i=0; i<nproc; i++) 
 
1720
    {
 
1721
 
 
1722
      start = 0; end = COUNT*NUMAGG; 
 
1723
      for(j=start, k=0; j<end; j+=NUMAGG, k++) 
 
1724
      {
 
1725
        src_ptr[k] = (void *)&dsrc[i][j];
 
1726
        dst_ptr[k] = (void *)&ddst_get[me][i*elems[1]+j];
 
1727
      }
 
1728
      darr.src_ptr_array = src_ptr;
 
1729
      darr.dst_ptr_array = dst_ptr;
 
1730
      darr.bytes = NUMAGG*sizeof(double);
 
1731
      darr.ptr_array_len = k;
 
1732
      if((rc=ARMCI_NbGetV(&darr, 1, i, NULL)))
 
1733
        ARMCI_Error("armci_nbgetv failed\n", rc);
 
1734
 
 
1735
      start = end; end = start + COUNT*NUMAGG;
 
1736
      for(j=start; j<end; j+=NUMAGG) 
 
1737
      {  
 
1738
        bytes = sizeof(double)*NUMAGG;
 
1739
        if((rc=ARMCI_NbGetS(&dsrc[i][j], NULL, &ddst_get[me][i*elems[1]+j], NULL, 
 
1740
                            &bytes, 0, i, NULL)))
 
1741
          ARMCI_Error("armci_nbputs failed\n",rc);
 
1742
      }
 
1743
 
 
1744
      start = end; end = elems[1];
 
1745
      for(j=start; j<end; j+=NUMAGG) 
 
1746
      {  
 
1747
        bytes = sizeof(double)*NUMAGG;
 
1748
        if((rc=ARMCI_NbGet(&dsrc[i][j], &ddst_get[me][i*elems[1]+j], bytes,
 
1749
                           i, NULL)))
 
1750
          ARMCI_Error("armci_nbget failed\n",rc);
 
1751
      }
 
1752
   }
 
1753
 
 
1754
    ARMCI_WaitAll(); 
 
1755
        
 
1756
    
 
1757
    MP_BARRIER();
 
1758
    ARMCI_AllFence();
 
1759
    MP_BARRIER();
 
1760
    
 
1761
    fprintf(stderr,"nproc: %d, elems[1]: %d\n", nproc, elems[1]);
 
1762
    for(i=0; i<nproc; i++) 
 
1763
    {
 
1764
      for(j=0; j<elems[1]; j++) 
 
1765
      {
 
1766
        if( ARMCI_ABS(ddst_put[me][i*elems[1]+j]-j*1.001*(i+1)) > 0.1) 
 
1767
         {
 
1768
            fprintf(stderr,"ddst_put[%d][%d*elems[1]+%d]-%d*1.001*(%d+1): %ld (elems[1]: %d)\n",
 
1769
                     me, i, j, j, i, ddst_put[me][i*elems[1]+j]-j*1.001*(i+1), elems[1]);
 
1770
          ARMCI_Error("implicit handle(s) failed...(a)", 0);
 
1771
        }
 
1772
      }
 
1773
    }
 
1774
    MP_BARRIER();
 
1775
 
 
1776
    for(i=0; i<nproc; i++) {
 
1777
      for(j=0; j<elems[1]; j++) {
 
1778
        if( ARMCI_ABS(ddst_get[me][i*elems[1]+j]-j*1.001*(i+1)) > 0.1) {
 
1779
          ARMCI_Error("implicit handles(s) failed...(b)", 0);
 
1780
        }
 
1781
      }
 
1782
    }
 
1783
 
 
1784
    MP_BARRIER();
 
1785
    ARMCI_AllFence();
 
1786
    MP_BARRIER();
 
1787
    
 
1788
    if(me==0){printf("O.K.\n\n"); fflush(stdout);}
 
1789
    destroy_array((void **)ddst_put);
 
1790
    destroy_array((void **)ddst_get);
 
1791
    destroy_array((void **)dsrc);
 
1792
}
 
1793
 
 
1794
 
 
1795
/* we need to rename main if linking with frt compiler */
 
1796
#ifdef FUJITSU_FRT
 
1797
#define main MAIN__
 
1798
#endif
 
1799
 
 
1800
int main(int argc, char* argv[])
 
1801
{
 
1802
    int ndim;
 
1803
 
 
1804
    MP_INIT(argc, argv);
 
1805
    MP_PROCS(&nproc);
 
1806
    MP_MYID(&me);
 
1807
 
 
1808
/*    printf("nproc = %d, me = %d\n", nproc, me);*/
 
1809
    
 
1810
    if(nproc>MAXPROC && me==0)
 
1811
       ARMCI_Error("Test works for up to %d processors\n",MAXPROC);
 
1812
 
 
1813
    if(me==0){
 
1814
       printf("ARMCI test program (%d processes)\n",nproc); 
 
1815
       fflush(stdout);
 
1816
       sleep(1);
 
1817
    }
 
1818
 
 
1819
    ARMCI_Init_args(&argc, &argv);
 
1820
 
 
1821
/*
 
1822
       if(me==1)armci_die("process 1 committing suicide",1);
 
1823
*/
 
1824
        if(me==0){
 
1825
           printf("\nTesting strided gets and puts\n");
 
1826
           printf("(Only std output for process 0 is printed)\n\n"); 
 
1827
           fflush(stdout);
 
1828
           sleep(1);
 
1829
        }
 
1830
        for(ndim=1; ndim<= MAXDIMS; ndim++) test_dim(ndim);
 
1831
        ARMCI_AllFence();
 
1832
        MP_BARRIER();
 
1833
 
 
1834
        if(me==0){
 
1835
           printf("\nTesting non-blocking gets and puts\n");
 
1836
           fflush(stdout);
 
1837
           sleep(1);
 
1838
        }
 
1839
        test_nbdim(); 
 
1840
        ARMCI_AllFence();
 
1841
        MP_BARRIER();
 
1842
 
 
1843
        if(me==0){
 
1844
           printf("\nTesting non-blocking vector gets and puts\n");
 
1845
           fflush(stdout);
 
1846
           sleep(1);
 
1847
        }
 
1848
        test_vec_small();
 
1849
        ARMCI_AllFence();
 
1850
        MP_BARRIER();
 
1851
 
 
1852
        if(me==0){
 
1853
           printf("\nTesting atomic accumulate\n");
 
1854
           fflush(stdout);
 
1855
           sleep(1);
 
1856
        }
 
1857
        for(ndim=1; ndim<= MAXDIMS; ndim++) test_acc(ndim); 
 
1858
        ARMCI_AllFence();
 
1859
        MP_BARRIER();
 
1860
 
 
1861
        if(me==0){
 
1862
           printf("\nTesting Vector Interface using triangular patches of a 2-D array\n\n");
 
1863
           fflush(stdout);
 
1864
           sleep(1);
 
1865
        }
 
1866
 
 
1867
        test_vector();
 
1868
        ARMCI_AllFence();
 
1869
        MP_BARRIER();
 
1870
 
 
1871
        if(me==0){
 
1872
           printf("\nTesting Accumulate with Vector Interface\n\n");
 
1873
           fflush(stdout);
 
1874
           sleep(1);
 
1875
        }
 
1876
        test_vector_acc();
 
1877
 
 
1878
        ARMCI_AllFence();
 
1879
        MP_BARRIER();
 
1880
 
 
1881
        if(me==0){
 
1882
           printf("\nTesting atomic fetch&add\n");
 
1883
           printf("(Std Output for all processes is printed)\n\n"); 
 
1884
           fflush(stdout);
 
1885
           sleep(1);
 
1886
        }
 
1887
        MP_BARRIER();
 
1888
 
 
1889
        test_fetch_add();
 
1890
 
 
1891
        ARMCI_AllFence();
 
1892
        MP_BARRIER();
 
1893
 
 
1894
        if(me==0){
 
1895
           printf("\nTesting atomic swap\n");
 
1896
           fflush(stdout);
 
1897
        }
 
1898
        test_swap();
 
1899
        ARMCI_AllFence();
 
1900
        MP_BARRIER();
 
1901
 
 
1902
        if(me==0){
 
1903
           printf("\nTesting register-originated put and get\n");
 
1904
           fflush(stdout);
 
1905
           sleep(1);
 
1906
        }
 
1907
        test_rput(); 
 
1908
        ARMCI_AllFence();
 
1909
        MP_BARRIER();
 
1910
 
 
1911
        if(me==0){
 
1912
          printf("\nTesting aggregate put/get requests\n");
 
1913
          fflush(stdout);
 
1914
        }
 
1915
        
 
1916
        /** 
 
1917
         * Aggregate put/get requests cannot be tested for\ number of procs 
 
1918
         * greater than 32. (Current implementation of aggregate put/get 
 
1919
         * can use at the maximum of 32 handles (defined by macro 
 
1920
         * _MAX_AGG_BUFFERS in aggregate.c). This test case is written in 
 
1921
         * such a way that each process puts/gets data to all the other 
 
1922
         * processes, thus the number of aggregate handle used is equal to 
 
1923
         * the number of processes created.
 
1924
        */
 
1925
        if(nproc > 32) {
 
1926
          if(me==0){
 
1927
            printf("\n WARNING: Aggregate put/get requests cannot be tested for number of procs greater than 32.\n\n");
 
1928
            fflush(stdout);
 
1929
          }
 
1930
        }
 
1931
        else
 
1932
          test_aggregate();
 
1933
        
 
1934
        ARMCI_AllFence();
 
1935
        MP_BARRIER();
 
1936
 
 
1937
        if(me==0){
 
1938
          printf("\nTesting implicit handles\n");
 
1939
          fflush(stdout);
 
1940
        }
 
1941
        test_implicit();
 
1942
        
 
1943
        ARMCI_AllFence();
 
1944
        MP_BARRIER();
 
1945
 
 
1946
 
 
1947
        MP_BARRIER();
 
1948
        /*test_memlock();*/
 
1949
 
 
1950
        MP_BARRIER();
 
1951
        if(me==0){printf("All tests passed\n"); fflush(stdout);}
 
1952
    sleep(2);
 
1953
 
 
1954
#ifdef NEWMALLOC
 
1955
    {
 
1956
      int i,j;
 
1957
      for(i=0; i<g_idx; i++) 
 
1958
        for(j=0; j<nproc; j++) 
 
1959
          ARMCI_Memdt(&meminfo[i][j], 0);
 
1960
      for(i=0; i<g_idx; i++) 
 
1961
        ARMCI_Memctl(&meminfo[i][me]);
 
1962
    }
 
1963
#endif
 
1964
    
 
1965
    MP_BARRIER();
 
1966
    ARMCI_Finalize();
 
1967
    MP_FINALIZE();
 
1968
    return(0);
 
1969
}