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

« back to all changes in this revision

Viewing changes to src/tools/ga-5-2/armci/testing/test_groups.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_groups.c,v 1.3 2004-11-22 20:29:53 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
/*#include "armcip.h"*/
 
25
 
 
26
#define MAXDIMS 7
 
27
#define MAXPROC 128
 
28
#define MINPROC 4
 
29
 
 
30
/***************************** macros ************************/
 
31
#define COPY(src, dst, bytes) memcpy((dst),(src),(bytes))
 
32
#define ABS(a)   (((a) >= 0) ? (a) : (-(a)))
 
33
#define MIN(a,b) (((a)<(b)) ? (a) : (b))
 
34
 
 
35
/***************************** global data *******************/
 
36
int me, nproc;
 
37
void *work[MAXPROC]; /* work array for propagating addresses */
 
38
 
 
39
#ifdef PVM
 
40
void pvm_init(int argc, char *argv[])
 
41
{
 
42
  int mytid, mygid, ctid[MAXPROC];
 
43
  int np, i;
 
44
 
 
45
  mytid = pvm_mytid();
 
46
  if ((argc != 2) && (argc != 1)) {
 
47
    goto usage;
 
48
  }
 
49
  if (argc == 1) {
 
50
    np = 1;
 
51
  }
 
52
  if (argc == 2)
 
53
    if ((np = atoi(argv[1])) < 1) {
 
54
      goto usage;
 
55
    }
 
56
  if (np > MAXPROC) {
 
57
    goto usage;
 
58
  }
 
59
 
 
60
  mygid = pvm_joingroup(MPGROUP);
 
61
 
 
62
  if (np > 1)
 
63
    if (mygid == 0) {
 
64
      i = pvm_spawn(argv[0], argv + 1, 0, "", np - 1, ctid);
 
65
    }
 
66
 
 
67
  while (pvm_gsize(MPGROUP) < np) {
 
68
    sleep(1);
 
69
  }
 
70
 
 
71
  /* sync */
 
72
  pvm_barrier(MPGROUP, np);
 
73
 
 
74
  printf("PVM initialization done!\n");
 
75
 
 
76
  return;
 
77
 
 
78
usage:
 
79
  fprintf(stderr, "usage: %s <nproc>\n", argv[0]);
 
80
  pvm_exit();
 
81
  exit(-1);
 
82
}
 
83
#endif
 
84
 
 
85
void create_array(void *a[], int elem_size, int ndim, int dims[])
 
86
{
 
87
  int bytes = elem_size, i, rc;
 
88
 
 
89
  assert(ndim <= MAXDIMS);
 
90
  for (i = 0; i < ndim; i++) {
 
91
    bytes *= dims[i];
 
92
  }
 
93
 
 
94
  rc = ARMCI_Malloc(a, bytes);
 
95
  assert(rc == 0);
 
96
 
 
97
  assert(a[me]);
 
98
 
 
99
}
 
100
 
 
101
void destroy_array(void *ptr[])
 
102
{
 
103
  ARMCI_Barrier();
 
104
 
 
105
  assert(!ARMCI_Free(ptr[me]));
 
106
}
 
107
 
 
108
#define GNUM_A 3
 
109
#define GNUM_B 2
 
110
#define ELEMS 10
 
111
 
 
112
/* to check if a process belongs to this group */
 
113
int chk_grp_membership(int rank, ARMCI_Group *grp, int *memberlist)
 
114
{
 
115
  int i, grp_size;
 
116
  ARMCI_Group_size(grp, &grp_size);
 
117
  for (i = 0; i < grp_size; i++) if (rank == memberlist[i]) {
 
118
      return 1;
 
119
    }
 
120
  return 0;
 
121
}
 
122
 
 
123
void test_one_group(ARMCI_Group *group, int *pid_list)
 
124
{
 
125
  int grp_me, grp_size;
 
126
  int i, j, src_proc, dst_proc;
 
127
  double *ddst_put[MAXPROC];
 
128
  double dsrc[ELEMS];
 
129
  int bytes, world_me;
 
130
 
 
131
  world_me = armci_msg_me();
 
132
  ARMCI_Group_rank(group, &grp_me);
 
133
  ARMCI_Group_size(group, &grp_size);
 
134
  if (grp_me == 0) {
 
135
    printf("GROUP SIZE = %d\n", grp_size);
 
136
  }
 
137
  printf("%d:group rank = %d\n", me, grp_me);
 
138
 
 
139
  src_proc = 0;
 
140
  dst_proc = grp_size - 1;
 
141
 
 
142
  bytes = ELEMS * sizeof(double);
 
143
  ARMCI_Malloc_group((void **)ddst_put, bytes, group);
 
144
 
 
145
  for (i = 0; i < ELEMS; i++) {
 
146
    dsrc[i] = i * 1.001 * (grp_me + 1);
 
147
  }
 
148
  for (i = 0; i < ELEMS; i++) {
 
149
    ddst_put[grp_me][i] = -1.0;
 
150
  }
 
151
 
 
152
  armci_msg_group_barrier(group);
 
153
 
 
154
  if (grp_me == src_proc) {
 
155
    /* NOTE: make sure to specify absolute ids in ARMCI calls */
 
156
    ARMCI_Put(dsrc, &ddst_put[dst_proc][0], bytes,
 
157
              ARMCI_Absolute_id(group, dst_proc));
 
158
  }
 
159
 
 
160
  armci_msg_group_barrier(group);
 
161
  /* NOTE: make sure to specify absolute ids in ARMCI calls */
 
162
  ARMCI_Fence(ARMCI_Absolute_id(group, dst_proc));
 
163
  sleep(1);
 
164
 
 
165
 
 
166
  /* Verify*/
 
167
  if (grp_me == dst_proc) {
 
168
    for (j = 0; j < ELEMS; j++) {
 
169
      if (ABS(ddst_put[grp_me][j] - j * 1.001 *(src_proc + 1)) > 0.1) {
 
170
        printf("\t%d: ddst_put[%d][%d] = %f and expected value is %f\n",
 
171
               me, grp_me, j, ddst_put[grp_me][j], j * 1.001 *(src_proc + 1));
 
172
        ARMCI_Error("groups: armci put failed...1", 0);
 
173
      }
 
174
    }
 
175
    printf("\n%d(%d): Test O.K. Verified\n", dst_proc, world_me);
 
176
  }
 
177
  armci_msg_group_barrier(group);
 
178
  ARMCI_Free_group(ddst_put[grp_me], group);
 
179
}
 
180
 
 
181
 
 
182
void test_groups()
 
183
{
 
184
 
 
185
  int pid_listA[MAXPROC]  = {0, 1, 2};
 
186
  int pid_listB[MAXPROC] = {1, 3};
 
187
  ARMCI_Group groupA, groupB;
 
188
 
 
189
  ARMCI_Barrier();
 
190
 
 
191
  ARMCI_Group_create(GNUM_A, pid_listA, &groupA); /* create group 1 */
 
192
  ARMCI_Group_create(GNUM_B, pid_listB, &groupB); /* create group 2 */
 
193
 
 
194
 
 
195
  /* ------------------------ GROUP A ------------------------- */
 
196
  if (chk_grp_membership(me, &groupA, pid_listA)) { /* group A */
 
197
    test_one_group(&groupA, pid_listA);
 
198
  }
 
199
 
 
200
  ARMCI_Barrier();
 
201
 
 
202
  /* ------------------------ GROUP B ------------------------- */
 
203
  if (chk_grp_membership(me, &groupB, pid_listB)) { /* group B */
 
204
    test_one_group(&groupB, pid_listB);
 
205
  }
 
206
 
 
207
  ARMCI_AllFence();
 
208
  ARMCI_Barrier();
 
209
 
 
210
  if (me == 0) {
 
211
    printf("O.K.\n");
 
212
    fflush(stdout);
 
213
  }
 
214
}
 
215
 
 
216
/**
 
217
 * Random permutation of 0..n-1 into an array.
 
218
 */
 
219
void random_permute(int *arr, int n)
 
220
{
 
221
  int i, j;
 
222
  int *vtmp = (int *)malloc(n * sizeof(int));
 
223
  assert(vtmp != NULL);
 
224
  for (i = 0; i < n; ++i) {
 
225
    vtmp[i] = -1;
 
226
  }
 
227
  for (i = 0; i < n; i++) {
 
228
    while (vtmp[j=(rand()%n)] != -1) /*no-op*/;
 
229
    assert(vtmp[j] == -1);
 
230
    vtmp[j] = 0;
 
231
    arr[i] = j;
 
232
  }
 
233
  free(vtmp);
 
234
}
 
235
 
 
236
int int_compare(const void *v1, const void *v2)
 
237
{
 
238
  int i1 = *(int *)v1, i2 = *(int *)v2;
 
239
  if (i1 < i2) {
 
240
    return -1;
 
241
  }
 
242
  if (i1 > i2) {
 
243
    return +1;
 
244
  }
 
245
  return 0;
 
246
}
 
247
 
 
248
/**
 
249
 * Test routine for non-collective process group management. This test
 
250
 * should not be used with MPI process group implementation.
 
251
 */
 
252
#define GROUP_SIZE 2
 
253
#define MAX_GROUPS (MAXPROC/GROUP_SIZE)
 
254
void test_groups_noncollective()
 
255
{
 
256
  int *pid_lists[MAX_GROUPS];
 
257
  int pids[MAXPROC];
 
258
  int i, nprocs, world_me;
 
259
  ARMCI_Group group;
 
260
  int *my_pid_list = NULL, my_grp_size = 0;
 
261
  int ngrps;
 
262
 
 
263
  ARMCI_Barrier();
 
264
  nprocs = armci_msg_nproc();
 
265
  world_me = armci_msg_me();
 
266
 
 
267
  random_permute(pids, nproc);
 
268
 
 
269
  ngrps = nprocs / GROUP_SIZE;
 
270
 
 
271
  for (i = 0; i < nprocs / GROUP_SIZE; i++) {
 
272
    pid_lists[i] = pids + (i * GROUP_SIZE);
 
273
  }
 
274
 
 
275
  for (i = 0; i < nprocs; i++) {
 
276
    if (pids[i] == world_me) {
 
277
      int grp_id = MIN(i / GROUP_SIZE, ngrps - 1);
 
278
      my_pid_list = pid_lists[grp_id];
 
279
      if (grp_id == ngrps - 1) {
 
280
        my_grp_size =  GROUP_SIZE + (nprocs % GROUP_SIZE);
 
281
      }
 
282
      else {
 
283
        my_grp_size = GROUP_SIZE;
 
284
      }
 
285
    }
 
286
  }
 
287
 
 
288
  qsort(my_pid_list, my_grp_size, sizeof(int), int_compare);
 
289
 
 
290
  ARMCI_Barrier();
 
291
  /*now create all these disjoint groups and test them in parallel*/
 
292
 
 
293
  ARMCI_Group_create(my_grp_size, my_pid_list, &group);
 
294
 
 
295
  test_one_group(&group, my_pid_list);
 
296
 
 
297
  ARMCI_Group_free(&group);
 
298
 
 
299
  ARMCI_AllFence();
 
300
  ARMCI_Barrier();
 
301
 
 
302
  if (world_me == 0) {
 
303
    printf("O.K.\n");
 
304
    fflush(stdout);
 
305
  }
 
306
}
 
307
 
 
308
 
 
309
int main(int argc, char *argv[])
 
310
{
 
311
  armci_msg_init(&argc, &argv);
 
312
  ARMCI_Init_args(&argc, &argv);
 
313
  nproc = armci_msg_nproc();
 
314
  me = armci_msg_me();
 
315
 
 
316
  /*    printf("nproc = %d, me = %d\n", nproc, me);*/
 
317
 
 
318
  if (nproc < MINPROC) {
 
319
    if (0 == me) {
 
320
      printf("Test needs at least %d processors (%d used)\n",
 
321
             MINPROC, nproc);
 
322
    }
 
323
    ARMCI_Barrier();
 
324
    armci_msg_finalize();
 
325
    exit(0);
 
326
  }
 
327
  if (nproc > MAXPROC) {
 
328
    if (0 == me) {
 
329
      printf("Test works for up to %d processors (%d used)\n",
 
330
             MAXPROC, nproc);
 
331
    }
 
332
    ARMCI_Barrier();
 
333
    armci_msg_finalize();
 
334
    exit(0);
 
335
  }
 
336
 
 
337
  if (me == 0) {
 
338
    printf("ARMCI test program (%d processes)\n", nproc);
 
339
    fflush(stdout);
 
340
    sleep(1);
 
341
  }
 
342
 
 
343
  if (me == 0) {
 
344
    printf("\n Testing ARMCI Groups!\n\n");
 
345
    fflush(stdout);
 
346
  }
 
347
 
 
348
  test_groups();
 
349
 
 
350
  ARMCI_AllFence();
 
351
  ARMCI_Barrier();
 
352
  if (me == 0) {
 
353
    printf("\n Collective groups: Success!!\n");
 
354
    fflush(stdout);
 
355
  }
 
356
  sleep(2);
 
357
 
 
358
#ifdef ARMCI_GROUP
 
359
  test_groups_noncollective();
 
360
 
 
361
  ARMCI_AllFence();
 
362
  ARMCI_Barrier();
 
363
  if (me == 0) {
 
364
    printf("\n Non-collective groups: Success!!\n");
 
365
    fflush(stdout);
 
366
  }
 
367
  sleep(2);
 
368
#endif
 
369
 
 
370
  ARMCI_Barrier();
 
371
  ARMCI_Finalize();
 
372
  armci_msg_finalize();
 
373
  return(0);
 
374
}