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

« back to all changes in this revision

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