~ubuntu-branches/ubuntu/trusty/nwchem/trusty-proposed

« back to all changes in this revision

Viewing changes to src/tools/ga-5-1/armci/testing/test.c

  • Committer: Package Import Robot
  • Author(s): Michael Banck, Daniel Leidert, Andreas Tille, Michael Banck
  • Date: 2013-07-04 12:14:55 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20130704121455-5tvsx2qabor3nrui
Tags: 6.3-1
* New upstream release.
* Fixes anisotropic properties (Closes: #696361).
* New features include:
  + Multi-reference coupled cluster (MRCC) approaches
  + Hybrid DFT calculations with short-range HF 
  + New density-functionals including Minnesota (M08, M11) and HSE hybrid
    functionals
  + X-ray absorption spectroscopy (XAS) with TDDFT
  + Analytical gradients for the COSMO solvation model
  + Transition densities from TDDFT 
  + DFT+U and Electron-Transfer (ET) methods for plane wave calculations
  + Exploitation of space group symmetry in plane wave geometry optimizations
  + Local density of states (LDOS) collective variable added to Metadynamics
  + Various new XC functionals added for plane wave calculations, including
    hybrid and range-corrected ones
  + Electric field gradients with relativistic corrections 
  + Nudged Elastic Band optimization method
  + Updated basis sets and ECPs 

[ Daniel Leidert ]
* debian/watch: Fixed.

[ Andreas Tille ]
* debian/upstream: References

[ Michael Banck ]
* debian/upstream (Name): New field.
* debian/patches/02_makefile_flags.patch: Refreshed.
* debian/patches/06_statfs_kfreebsd.patch: Likewise.
* debian/patches/07_ga_target_force_linux.patch: Likewise.
* debian/patches/05_avoid_inline_assembler.patch: Removed, no longer needed.
* debian/patches/09_backported_6.1.1_fixes.patch: Likewise.
* debian/control (Build-Depends): Added gfortran-4.7 and gcc-4.7.
* debian/patches/10_force_gcc-4.7.patch: New patch, explicitly sets
  gfortran-4.7 and gcc-4.7, fixes test suite hang with gcc-4.8 (Closes:
  #701328, #713262).
* debian/testsuite: Added tests for COSMO analytical gradients and MRCC.
* debian/rules (MRCC_METHODS): New variable, required to enable MRCC methods.

Show diffs side-by-side

added added

removed removed

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