~ubuntu-branches/ubuntu/utopic/nwchem/utopic

« back to all changes in this revision

Viewing changes to src/tools/ga-5-1/armci/src-gemini/armci.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: armci.c,v 1.114.2.17 2007-08-30 22:58:18 manoj Exp $ */
6
 
 
7
 
/* DISCLAIMER
8
 
 *
9
 
 * This material was prepared as an account of work sponsored by an
10
 
 * agency of the United States Government.  Neither the United States
11
 
 * Government nor the United States Department of Energy, nor Battelle,
12
 
 * nor any of their employees, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR
13
 
 * ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
14
 
 * COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT,
15
 
 * SOFTWARE, OR PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT
16
 
 * INFRINGE PRIVATELY OWNED RIGHTS.
17
 
 *
18
 
 *
19
 
 * ACKNOWLEDGMENT
20
 
 *
21
 
 * This software and its documentation were produced with United States
22
 
 * Government support under Contract Number DE-AC06-76RLO-1830 awarded by
23
 
 * the United States Department of Energy.  The United States Government
24
 
 * retains a paid-up non-exclusive, irrevocable worldwide license to
25
 
 * reproduce, prepare derivative works, perform publicly and display
26
 
 * publicly by or for the US Government, including the right to
27
 
 * distribute to other US Government contractors.
28
 
 */
29
 
 
30
 
#define  EXTERN
31
 
/*#define  PRINT_BT*/
32
 
#define _GNU_SOURCE
33
 
#include <stdio.h>
34
 
#include <stdlib.h>
35
 
#include <assert.h>
36
 
#if defined(CRAY) && !defined(__crayx1)
37
 
#  include <sys/category.h>
38
 
#  include <sys/resource.h>
39
 
#  include <unistd.h>
40
 
#endif
41
 
#ifdef LAPI
42
 
#  include "lapidefs.h"
43
 
#endif
44
 
#include <errno.h>
45
 
#include "armcip.h"
46
 
#include "copy.h"
47
 
#include "memlock.h"
48
 
#include "shmem.h"
49
 
#include "signaltrap.h"
50
 
 
51
 
#ifdef ARMCIX
52
 
#include "x/armcix.h"
53
 
#endif
54
 
#ifdef BGML
55
 
#include "bgml.h"
56
 
#include <assert.h>
57
 
#include "bgmldefs.h"
58
 
extern void armci_msg_barrier(void);
59
 
#endif
60
 
 
61
 
#ifdef CRAY_SHMEM
62
 
#  ifdef CRAY_XT
63
 
#    include <mpp/shmem.h>
64
 
#  else
65
 
#    include <shmem.h>
66
 
#  endif
67
 
#endif
68
 
 
69
 
#include <malloc.h>
70
 
 
71
 
/* global variables */
72
 
int armci_me, armci_Sme, armci_nproc;
73
 
int armci_clus_me, armci_nclus, armci_master;
74
 
int armci_clus_first, armci_clus_last;
75
 
int *_armci_argc=NULL;
76
 
char ***_armci_argv=NULL;
77
 
int _armci_initialized_args=0;
78
 
int _armci_initialized=0;
79
 
int _armci_terminating =0;
80
 
thread_id_t armci_usr_tid;
81
 
armci_ireq_t armci_inb_handle[ARMCI_MAX_IMPLICIT];/*implicit non-blocking handle*/
82
 
#ifndef HITACHI
83
 
double armci_internal_buffer[BUFSIZE_DBL];
84
 
#endif
85
 
#if defined(SYSV) || defined(WIN32) || defined(MMAP) || defined(HITACHI) || defined(CATAMOUNT) || defined(BGML)
86
 
#   include "locks.h"
87
 
    lockset_t lockid;
88
 
#endif
89
 
 
90
 
int* armci_prot_switch_fence=NULL;
91
 
int armci_prot_switch_preproc = -1;
92
 
int armci_prot_switch_preop = -1;
93
 
 
94
 
#ifdef BGML
95
 
/*   void armci_allocate_locks(); */
96
 
   void armci_init_memlock();
97
 
#endif
98
 
 
99
 
#ifdef LIBELAN_ATOMICS
100
 
ELAN_ATOMIC *a;
101
 
#warning "Enabling new atomics"
102
 
#endif
103
 
 
104
 
typedef struct{
105
 
  int sent;
106
 
  int received;
107
 
  int waited;
108
 
}armci_notify_t;
109
 
 
110
 
armci_notify_t **_armci_notify_arr;
111
 
 
112
 
void ARMCI_Cleanup()
113
 
{
114
 
#if defined(DATA_SERVER)
115
 
#if defined(LIBONESIDED)
116
 
    dsTurnOff();
117
 
#else
118
 
    if(armci_nclus >1){
119
 
        armci_wait_for_server();
120
 
    }
121
 
#endif
122
 
#endif
123
 
 
124
 
#if (defined(SYSV) || defined(WIN32) || defined(MMAP))&& !defined(HITACHI) 
125
 
    Delete_All_Regions();
126
 
    if(armci_nproc>1)
127
 
#if !defined(LAPI) 
128
 
       DeleteLocks(lockid);
129
 
#endif
130
 
 
131
 
#ifndef WIN32
132
 
    ARMCI_RestoreSignals();
133
 
#endif
134
 
 
135
 
#endif
136
 
  armci_transport_cleanup();
137
 
 
138
 
}
139
 
 
140
 
int armci_getbufsize()
141
 
{
142
 
        return(BUFSIZE);
143
 
}
144
 
 
145
 
void armci_notify_init()
146
 
{
147
 
  int rc,bytes=sizeof(armci_notify_t)*armci_nproc;
148
 
 
149
 
#ifdef DOELAN4
150
 
  armci_elan_notify_init();
151
 
  return;
152
 
#endif
153
 
 
154
 
  _armci_notify_arr=
155
 
        (armci_notify_t**)malloc(armci_nproc*sizeof(armci_notify_t*));
156
 
  if(!_armci_notify_arr)armci_die("armci_notify_ini:malloc failed",armci_nproc);
157
 
 
158
 
  if((rc=PARMCI_Malloc((void **)_armci_notify_arr, bytes))) 
159
 
        armci_die(" armci_notify_init: armci_malloc failed",bytes); 
160
 
  bzero(_armci_notify_arr[armci_me], bytes);
161
 
}
162
 
 
163
 
 
164
 
static void armci_perror_msg()
165
 
{
166
 
    char perr_str[80];
167
 
    if(!errno)return;
168
 
    sprintf(perr_str,"Last System Error Message from Task %d:",armci_me);
169
 
    perror(perr_str);
170
 
}
171
 
 
172
 
static void armci_abort(int code)
173
 
{
174
 
    abort();
175
 
#if !defined(BGML)
176
 
    armci_perror_msg();
177
 
#endif
178
 
    ARMCI_Cleanup();
179
 
    /* data server process cannot use message-passing library to abort
180
 
     * it simply exits, parent will get SIGCHLD and abort the program
181
 
     */
182
 
#if defined(DATA_SERVER)
183
 
    if(armci_me<0)_exit(1);
184
 
    else
185
 
#endif
186
 
    armci_msg_abort(code);
187
 
}
188
 
 
189
 
 
190
 
void armci_die(char *msg, int code)
191
 
{
192
 
    void *bt[100];
193
 
 
194
 
    if(_armci_terminating)return;
195
 
    else _armci_terminating=1;
196
 
 
197
 
    if(SERVER_CONTEXT){
198
 
       fprintf(stdout,"%d(s):%s: %d\n",armci_me, msg, code); fflush(stdout);
199
 
    // fprintf(stderr,"%d(s):%s: %d\n",armci_me, msg, code);
200
 
    }else{
201
 
      fprintf(stdout,"%d:%s: %d\n",armci_me, msg, code); fflush(stdout);
202
 
    //fprintf(stderr,"%d:%s: %d\n",armci_me, msg, code);
203
 
    }
204
 
 
205
 
#ifdef PRINT_BT
206
 
    backtrace_symbols_fd(bt, backtrace(bt, 100), 2);
207
 
#endif
208
 
 
209
 
    armci_abort(code);
210
 
}
211
 
 
212
 
 
213
 
void armci_die2(char *msg, int code1, int code2)
214
 
{
215
 
    void *bt[100];
216
 
 
217
 
    if(_armci_terminating)return;
218
 
    else _armci_terminating=1;
219
 
 
220
 
    if(SERVER_CONTEXT){
221
 
      fprintf(stdout,"%d(s):%s: (%d,%d)\n",armci_me,msg,code1,code2);
222
 
      fflush(stdout);
223
 
      fprintf(stderr,"%d(s):%s: (%d,%d)\n",armci_me,msg,code1,code2);
224
 
    }else{
225
 
      fprintf(stdout,"%d:%s: (%d,%d)\n",armci_me,msg,code1,code2);
226
 
      fflush(stdout);
227
 
      fprintf(stderr,"%d:%s: (%d,%d)\n",armci_me,msg,code1,code2);
228
 
    }
229
 
#ifdef PRINT_BT
230
 
        backtrace_symbols_fd(bt, backtrace(bt, 100), 2);
231
 
#endif
232
 
    armci_abort(code1);
233
 
}
234
 
 
235
 
 
236
 
void ARMCI_Error(char *msg, int code)
237
 
{
238
 
    armci_die(msg,code);
239
 
}
240
 
 
241
 
 
242
 
void armci_allocate_locks()
243
 
{
244
 
    /* note that if ELAN_ACC is defined the scope of locks is limited to SMP */
245
 
#if !defined(CRAY_SHMEM) && (defined(HITACHI) || defined(CATAMOUNT) || \
246
 
    (defined(QUADRICS) && defined(_ELAN_LOCK_H) && !defined(ELAN_ACC)))
247
 
       armcill_allocate_locks(NUM_LOCKS);
248
 
#elif (defined(SYSV) || defined(WIN32) || defined(MMAP)) && !defined(HITACHI)
249
 
       if(armci_nproc == 1)return;
250
 
#  if defined(SPINLOCK) || defined(PMUTEXES)
251
 
       CreateInitLocks(NUM_LOCKS, &lockid);
252
 
#  else
253
 
       if(armci_master==armci_me)CreateInitLocks(NUM_LOCKS, &lockid);
254
 
       armci_msg_clus_brdcst(&lockid, sizeof(lockid));
255
 
       if(armci_master != armci_me)InitLocks(NUM_LOCKS, lockid);
256
 
#  endif
257
 
#endif
258
 
}
259
 
 
260
 
 
261
 
void ARMCI_Set_shm_limit(unsigned long shmemlimit)
262
 
{
263
 
#if (defined(SYSV) || defined(WIN32)  || defined(MMAP)) && !defined(HITACHI)
264
 
#define EXTRASHM  1024   /* extra shmem used internally in ARMCI */
265
 
unsigned long limit;
266
 
    limit = armci_clus_info[armci_clus_me].nslave * shmemlimit + EXTRASHM;
267
 
    armci_set_shmem_limit(limit);
268
 
#endif
269
 
}
270
 
 
271
 
 
272
 
 
273
 
/*\ allocate and initialize memory locking data structure
274
 
\*/
275
 
void armci_init_memlock()
276
 
{
277
 
    int bytes = MAX_SLOTS*sizeof(memlock_t);
278
 
    int rc, msize_per_proc=bytes;
279
 
    
280
 
#ifdef MEMLOCK_SHMEM_FLAG    
281
 
    /* last proc on node allocates memlock flag in shmem */
282
 
    if(armci_clus_last == armci_me) bytes += sizeof(int);
283
 
#endif
284
 
 
285
 
    memlock_table_array = malloc(armci_nproc*sizeof(void*));
286
 
    if(!memlock_table_array) armci_die("malloc failed for ARMCI lock array",0);
287
 
 
288
 
    rc = PARMCI_Malloc(memlock_table_array, bytes);
289
 
    if(rc) armci_die("failed to allocate ARMCI memlock array",rc);
290
 
 
291
 
    armci_msg_barrier();
292
 
 
293
 
    bzero(memlock_table_array[armci_me],bytes);
294
 
 
295
 
#ifdef BGML
296
 
    bgml_init_locks ((void *) memlock_table_array[armci_me]);
297
 
#elif ARMCIX
298
 
    ARMCIX_init_memlock ((memlock_t *) memlock_table_array[armci_me]);
299
 
#endif
300
 
 
301
 
 
302
 
#ifdef MEMLOCK_SHMEM_FLAG    
303
 
    /* armci_use_memlock_table is a pointer to local memory variable=1
304
 
     * we overwrite the pointer with address of shared memory variable 
305
 
     * armci_use_memlock_table and initialize it >0
306
 
     */
307
 
    armci_use_memlock_table = (int*) (msize_per_proc + 
308
 
                              (char*) memlock_table_array[armci_clus_last]);  
309
 
                              
310
 
    /* printf("%d: last=%d bytes=%d ptr =(%d, %d)\n",
311
 
           armci_me,armci_clus_last,bytes,armci_use_memlock_table,  
312
 
           memlock_table_array[armci_clus_last]); fflush(stdout); */
313
 
 
314
 
    if(armci_clus_last == armci_me) *armci_use_memlock_table =1+armci_me;
315
 
 
316
 
#endif
317
 
 
318
 
    *armci_use_memlock_table = 0;
319
 
    armci_msg_barrier();
320
 
}
321
 
 
322
 
 
323
 
#if defined(SYSV) || defined(WIN32)
324
 
static void armci_check_shmmax()
325
 
{
326
 
  long mylimit, limit;
327
 
  mylimit = limit = (long) armci_max_region();
328
 
  armci_msg_bcast_scope(SCOPE_MASTERS, &limit, sizeof(long), 0);
329
 
  if(mylimit != limit){
330
 
     printf("%d:Shared mem limit in ARMCI is %ld bytes on node %s vs %ld on %s\n",
331
 
            armci_me,mylimit<<10,armci_clus_info[armci_clus_me].hostname,
332
 
            limit<<10, armci_clus_info[0].hostname);
333
 
     fflush(stdout); sleep(1);
334
 
     armci_die("All nodes must have the same SHMMAX limit if NO_SHM is not defined",0);
335
 
  }
336
 
}
337
 
#endif
338
 
 
339
 
extern void armci_region_shm_malloc(void *ptr_arr[], size_t bytes);
340
 
 
341
 
 
342
 
void ARMCI_NetInit()
343
 
{
344
 
  /*armci_portals_net_init();*/
345
 
}
346
 
 
347
 
int PARMCI_Init_args(int *argc, char ***argv)
348
 
{
349
 
    armci_msg_init(argc,argv);
350
 
 
351
 
    _armci_argc = argc;
352
 
    _armci_argv = argv;
353
 
    _armci_initialized_args=1;
354
 
    PARMCI_Init();
355
 
}
356
 
 
357
 
 
358
 
extern void *sbrk(intptr_t);
359
 
extern void code_summary();
360
 
 
361
 
int PARMCI_Init()
362
 
{
363
 
    caddr_t atbeginbrval = (caddr_t)sbrk(0);
364
 
    if(_armci_initialized>0) return 0;
365
 
#ifdef NEW_MALLOC
366
 
    mallopt(M_MMAP_MAX, 0);
367
 
    mallopt(M_TRIM_THRESHOLD, -1);
368
 
#endif
369
 
 
370
 
    armci_msg_init(NULL, NULL);
371
 
 
372
 
    armci_nproc = armci_msg_nproc();
373
 
    armci_me = armci_msg_me();
374
 
    armci_usr_tid = THREAD_ID_SELF(); /*remember the main user thread id */
375
 
    armci_init_clusinfo();
376
 
    armci_prot_switch_fence = malloc(sizeof(int*)*armci_nproc);
377
 
    assert(armci_prot_switch_fence !=NULL);
378
 
  # ifdef LIBONESIDED
379
 
    armci_onesided_init();
380
 
  # endif
381
 
#ifdef MPI
382
 
    armci_group_init();
383
 
#endif
384
 
#ifndef NEW_MALLOC
385
 
    armci_krmalloc_init_localmem();
386
 
#endif
387
 
#if defined(SYSV) || defined(WIN32) || defined(MMAP)
388
 
    if(ARMCI_Uses_shm() ) {
389
 
      armci_shmem_init();
390
 
    }
391
 
#endif
392
 
    armci_allocate_locks();
393
 
    armci_init_fence();
394
 
#if ARMCI_ENABLE_GPC_CALLS
395
 
    gpc_init_signals();
396
 
#endif
397
 
    armci_msg_barrier();
398
 
    armci_init_memlock(); /* allocate data struct for locking memory areas */
399
 
    armci_msg_barrier();
400
 
    //if(armci_me == 0) code_summary();
401
 
    armci_msg_barrier();
402
 
    armci_msg_gop_init();
403
 
    _armci_initialized++;
404
 
    return 0;
405
 
}
406
 
 
407
 
 
408
 
void PARMCI_Finalize()
409
 
{
410
 
    if(!_armci_initialized)return;
411
 
    _armci_initialized--;
412
 
    if(_armci_initialized)return;
413
 
 
414
 
    _armci_terminating =1;
415
 
    armci_msg_barrier();
416
 
    if(armci_me==armci_master) ARMCI_ParentRestoreSignals();
417
 
 
418
 
#ifdef PORTALS
419
 
    request_header_t msg;
420
 
    portals_ds_req_t req;
421
 
    ptl_process_id_t dsid = portals_id_map[armci_me];
422
 
    msg.operation = QUIT;
423
 
 
424
 
    if(armci_me == armci_master) {
425
 
       portalsBlockingRemoteOperationToNode(&msg,sizeof(request_header_t),armci_clus_me);
426
 
    }
427
 
 
428
 
    armci_msg_barrier();
429
 
    portals_cp_finalize();
430
 
 
431
 
#else
432
 
 
433
 
    ARMCI_Cleanup();
434
 
    armci_msg_barrier();
435
 
    armci_group_finalize();
436
 
    free(armci_prot_switch_fence);
437
 
#endif
438
 
#ifdef MPI
439
 
    MPI_Comm_free(&ARMCI_COMM_WORLD); /*JD: free at last*/
440
 
#endif
441
 
}
442
 
 
443
 
 
444
 
/* Indicates whether ARMCI_Init or ARMCI_Init_args has been called. */
445
 
int PARMCI_Initialized()
446
 
{
447
 
    return (_armci_initialized > 0) ? 1 : 0;
448
 
}
449
 
 
450
 
 
451
 
#if !(defined(SYSV) || defined(WIN32))
452
 
void ARMCI_Set_shmem_limit(unsigned long shmemlimit)
453
 
{
454
 
   /* not applicable here
455
 
    * aborting would  make user's life harder
456
 
    */
457
 
}
458
 
#endif
459
 
 
460
 
 
461
 
 
462
 
void ARMCI_Copy(void *src, void *dst, int n)
463
 
{
464
 
 armci_copy(src,dst,n);
465
 
}
466
 
 
467
 
extern void cpu_yield();
468
 
void armci_util_wait_int(volatile int *p, int val, int maxspin)
469
 
{
470
 
int count=0;
471
 
extern void cpu_yield();
472
 
       while(*p != val)
473
 
            if((++count)<maxspin);
474
 
            else{
475
 
               /*printf("\n%d:flag=%d val=%d",armci_me,*p,val);*/
476
 
               cpu_yield();
477
 
               count =0;
478
 
#if defined(MACX) && defined(__ppc__) && defined(__GNUC__)
479
 
               __asm__ __volatile__ ("sync" ::: "memory");
480
 
#endif
481
 
               __asm__ __volatile__ ("mfence" ::: "memory");
482
 
               __asm__ __volatile__ ("sfence" ::: "memory");
483
 
            }
484
 
}
485
 
void armci_util_wait_long(volatile long *p, long val, int maxspin)
486
 
 {
487
 
int count=0;
488
 
extern void cpu_yield();
489
 
       while(*p != val)
490
 
            if((++count)<maxspin);
491
 
            else{
492
 
               /*printf("\n%d:flag=%d val=%d",armci_me,*p,val);*/
493
 
               cpu_yield();
494
 
               count =0;
495
 
#if defined(MACX) && defined(__ppc__) && defined(__GNUC__)
496
 
               __asm__ __volatile__ ("sync" ::: "memory");
497
 
#endif
498
 
               __asm__ __volatile__ ("mfence" ::: "memory");
499
 
               __asm__ __volatile__ ("sfence" ::: "memory");
500
 
            }
501
 
502
 
 
503
 
/*\ returns 1 if specified process resides on the same smp node as calling task 
504
 
\*/
505
 
int ARMCI_Same_node(int proc)
506
 
{
507
 
   int direct=SAMECLUSNODE(proc);
508
 
   return direct;
509
 
}
510
 
 
511
 
/*\ blocks the calling process until a nonblocking operation represented
512
 
 *  by the user handle completes
513
 
\*/
514
 
int PARMCI_Wait(armci_hdl_t* usr_hdl){
515
 
armci_ihdl_t nb_handle = (armci_ihdl_t)usr_hdl;
516
 
int success=0;
517
 
int direct=SAMECLUSNODE(nb_handle->proc);
518
 
 
519
 
    if(direct) {
520
 
       return(success);
521
 
    }
522
 
    if(nb_handle) {
523
 
      if(nb_handle->agg_flag) {
524
 
        armci_agg_complete(nb_handle, UNSET);
525
 
        return (success);
526
 
      }
527
 
      if(nb_handle->tag!=0 && nb_handle->bufid==NB_NONE){
528
 
        ARMCI_NB_WAIT(nb_handle->cmpl_info);
529
 
               __asm__ __volatile__ ("mfence" ::: "memory");
530
 
               __asm__ __volatile__ ("sfence" ::: "memory");
531
 
        return(success);
532
 
      }
533
 
#     ifdef COMPLETE_HANDLE
534
 
       COMPLETE_HANDLE(nb_handle->bufid,nb_handle->tag,(&success));
535
 
#     endif
536
 
    }
537
 
 
538
 
               __asm__ __volatile__ ("mfence" ::: "memory");
539
 
               __asm__ __volatile__ ("sfence" ::: "memory");
540
 
    return(success);
541
 
}
542
 
 
543
 
/** 
544
 
 * implicit handle 
545
 
 */
546
 
static char hdl_flag[ARMCI_MAX_IMPLICIT];
547
 
static int impcount=0;
548
 
armci_ihdl_t armci_set_implicit_handle (int op, int proc) {
549
 
 
550
 
  int i=impcount%ARMCI_MAX_IMPLICIT;
551
 
  if(hdl_flag[i]=='1')
552
 
    PARMCI_Wait((armci_hdl_t*)&armci_inb_handle[i]);
553
 
 
554
 
#ifdef BGML
555
 
   armci_inb_handle[i].count=0;
556
 
#endif
557
 
  armci_inb_handle[i].tag   = GET_NEXT_NBTAG();
558
 
  armci_inb_handle[i].op    = op;
559
 
  armci_inb_handle[i].proc  = proc;
560
 
  armci_inb_handle[i].bufid = NB_NONE;
561
 
  armci_inb_handle[i].agg_flag = 0;
562
 
  hdl_flag[i]='1';
563
 
  ++impcount;
564
 
  return &armci_inb_handle[i];
565
 
}
566
 
 
567
 
 
568
 
/* wait for all non-blocking operations to finish */
569
 
int PARMCI_WaitAll (void) {
570
 
#ifdef BGML
571
 
  BGML_WaitAll();
572
 
#elif ARMCIX
573
 
  ARMCIX_WaitAll ();
574
 
#else
575
 
  int i;
576
 
  if(impcount) {
577
 
    for(i=0; i<ARMCI_MAX_IMPLICIT; i++) {
578
 
      if(hdl_flag[i] == '1') {
579
 
        PARMCI_Wait((armci_hdl_t*)&armci_inb_handle[i]);
580
 
        hdl_flag[i]='0';
581
 
      }
582
 
    }
583
 
  }
584
 
  impcount=0;
585
 
#endif
586
 
  return 0;
587
 
}
588
 
 
589
 
/* wait for all non-blocking operations to a particular process to finish */
590
 
int PARMCI_WaitProc (int proc) {
591
 
#ifdef BGML
592
 
  BGML_WaitProc(proc);
593
 
#elif ARMCIX
594
 
  ARMCIX_WaitProc (proc);
595
 
#else
596
 
  int i;
597
 
  if(impcount) {
598
 
    for(i=0; i<ARMCI_MAX_IMPLICIT; i++) {
599
 
      if(hdl_flag[i]=='1' && armci_inb_handle[i].proc==proc) {
600
 
        PARMCI_Wait((armci_hdl_t*)&armci_inb_handle[i]);
601
 
        hdl_flag[i]='0';
602
 
      }
603
 
    }
604
 
  }
605
 
#endif
606
 
  return 0;
607
 
}
608
 
 
609
 
static unsigned int _armci_nb_tag=0;
610
 
unsigned int _armci_get_next_tag(){
611
 
    return((++_armci_nb_tag));
612
 
}
613
 
 
614
 
void ARMCI_SET_AGGREGATE_HANDLE(armci_hdl_t* nb_handle) { 
615
 
      ((armci_ihdl_t)(nb_handle))->agg_flag = 1;
616
 
      ((armci_ihdl_t)(nb_handle))->proc = -1;
617
 
}
618
 
 
619
 
void ARMCI_UNSET_AGGREGATE_HANDLE(armci_hdl_t* nb_handle) {
620
 
      ((armci_ihdl_t)(nb_handle))->agg_flag = 0;
621
 
      ((armci_ihdl_t)(nb_handle))->proc = -1;
622
 
}
623
 
 
624
 
int armci_notify(int proc)
625
 
{
626
 
#ifdef DOELAN4
627
 
  if(proc==armci_me){
628
 
    return 0;
629
 
  }
630
 
#endif
631
 
#if defined(GM) || (defined(DOELAN4) && defined(ELAN_ACC))
632
 
  {
633
 
    extern int armci_inotify_proc(int);
634
 
    return(armci_inotify_proc(proc));
635
 
  }
636
 
#else
637
 
   armci_notify_t *pnotify = _armci_notify_arr[armci_me]+proc;
638
 
   pnotify->sent++;
639
 
# ifdef MEM_FENCE
640
 
   if(SAMECLUSNODE(proc)) MEM_FENCE;
641
 
# endif
642
 
   PARMCI_Put(&pnotify->sent,&(_armci_notify_arr[proc]+armci_me)->received, 
643
 
             sizeof(pnotify->sent),proc);
644
 
   return(pnotify->sent);
645
 
#endif
646
 
}
647
 
 
648
 
 
649
 
/*\ blocks until received count becomes >= waited count
650
 
 *  return received count and store waited count in *pval
651
 
\*/
652
 
int parmci_notify_wait(int proc,int *pval)
653
 
{
654
 
  int retval;
655
 
#ifdef DOELAN4
656
 
  if(proc==armci_me){
657
 
#ifdef MEM_FENCE
658
 
       MEM_FENCE;
659
 
#endif
660
 
    return 0;
661
 
  }
662
 
#endif
663
 
 
664
 
#if defined(GM) || (defined(DOELAN4) && defined(ELAN_ACC))
665
 
  {
666
 
     extern int armci_inotify_wait(int,int*);
667
 
     retval=armci_inotify_wait(proc,pval);
668
 
  }
669
 
#else
670
 
  {
671
 
     long loop=0;
672
 
     armci_notify_t *pnotify = _armci_notify_arr[armci_me]+proc;
673
 
     pnotify->waited++;
674
 
     while( pnotify->waited > pnotify->received) {
675
 
         if(++loop == 1000) { loop=0;cpu_yield(); }
676
 
         armci_util_spin(loop, pnotify);
677
 
     }
678
 
     *pval = pnotify->waited;
679
 
     retval=pnotify->received;
680
 
  }
681
 
#endif
682
 
 
683
 
  return retval;
684
 
}
685
 
 
686
 
long armci_util_long_getval(long* p)
687
 
{
688
 
   return *p;
689
 
}
690
 
 
691
 
int armci_util_int_getval(int* p)
692
 
{
693
 
   return *p;
694
 
}
695
 
 
696
 
 
697
 
int PARMCI_Test(armci_hdl_t *usr_hdl)
698
 
{
699
 
armci_ihdl_t nb_handle = (armci_ihdl_t)usr_hdl;
700
 
int success=0;
701
 
#ifdef BGML
702
 
   success=(int)nb_handle->count;
703
 
#else
704
 
int direct=SAMECLUSNODE(nb_handle->proc);
705
 
   if(direct)return(success);
706
 
    if(nb_handle) {
707
 
      if(nb_handle->agg_flag) {
708
 
         armci_die("test for aggregate handle not yet implemented\n",0);
709
 
      }
710
 
    }
711
 
    if(nb_handle){
712
 
#     ifdef ARMCI_NB_TEST
713
 
        if(nb_handle->tag==0){
714
 
              ARMCI_NB_TEST(nb_handle->cmpl_info,&success);
715
 
              return(success);
716
 
        }
717
 
#       ifdef LAPI
718
 
         if(nb_handle->tag!=0 && nb_handle->bufid==NB_NONE){
719
 
               ARMCI_NB_TEST(nb_handle->cmpl_info,&success);
720
 
               return(success);
721
 
         }
722
 
#       endif
723
 
#     endif
724
 
#     ifdef TEST_HANDLE
725
 
       TEST_HANDLE(nb_handle->bufid,nb_handle->tag,(&success));
726
 
#     endif
727
 
    }
728
 
#endif
729
 
    return(success);
730
 
}
731
 
 
732
 
#ifdef DO_CKPT
733
 
void ARMCI_Ckpt_create_ds(armci_ckpt_ds_t *ckptds, int count)
734
 
{
735
 
    armci_create_ckptds(ckptds,count);
736
 
}
737
 
 
738
 
int ARMCI_Ckpt_init(char *filename, ARMCI_Group *grp, int savestack, int saveheap, armci_ckpt_ds_t *ckptds)
739
 
{
740
 
int rid;
741
 
    rid = armci_icheckpoint_init(filename,grp,savestack,saveheap,ckptds);
742
 
    return(rid);
743
 
}
744
 
 
745
 
int ARMCI_Ckpt(int rid)
746
 
{
747
 
    return(armci_icheckpoint(rid));
748
 
}
749
 
 
750
 
void ARMCI_Ckpt_Recover(int rid, int iamreplacement)
751
 
{
752
 
    armci_irecover(rid, iamreplacement);
753
 
}
754
 
void ARMCI_Ckpt_finalize(int rid)
755
 
{
756
 
    armci_icheckpoint_finalize(rid);
757
 
}
758
 
#endif
759
 
#if ARMCI_ENABLE_GPC_CALLS
760
 
int armci_gpc(int hndl, int proc, void  *hdr, int hlen,  void *data,  int dlen,
761
 
              void *rhdr, int rhlen, void *rdata, int rdlen,
762
 
              armci_hdl_t* nbh) {
763
 
armci_ihdl_t nb_handle = (armci_ihdl_t)nbh;
764
 
armci_giov_t darr[2]; /* = {{&rhdr, &rhdr, 1, rhlen}, {&rdata, &rdata, 1, rdlen}};*/
765
 
gpc_send_t send;
766
 
char *ptr;
767
 
 
768
 
    /* initialize giov */
769
 
    darr[0].src_ptr_array = &rhdr;
770
 
    darr[0].dst_ptr_array = &rhdr;
771
 
    darr[0].ptr_array_len = 1;
772
 
    darr[0].bytes         = rhlen;
773
 
 
774
 
    darr[1].src_ptr_array = &rdata;
775
 
    darr[1].dst_ptr_array = &rdata;
776
 
    darr[1].ptr_array_len = 1;
777
 
    darr[1].bytes         = rdlen;
778
 
 
779
 
  
780
 
/*    if(hlen<0 || hlen>=ARMCI_Gpc_get_hlen()) */
781
 
/*      return FAIL2; */
782
 
/*    if(rhlen<0 || rhlen>=ARMCI_Gpc_get_hlen()) */
783
 
/*      return FAIL2; */
784
 
/*    if(dlen<0 || dlen>=ARMCI_Gpc_get_dlen())  */
785
 
/*      return FAIL2; */
786
 
/*    if(rdlen<0 || rdlen>=ARMCI_Gpc_get_dlen())  */
787
 
/*      return FAIL2; */
788
 
 
789
 
    if(hlen>0 && hdr==NULL) 
790
 
      return FAIL3;
791
 
    if(rhlen>0 && rhdr==NULL) 
792
 
      return FAIL3;
793
 
    if(dlen>0 && data==NULL) 
794
 
      return FAIL3;
795
 
    if(rdlen>0 && rdata==NULL) 
796
 
      return FAIL3;
797
 
 
798
 
    if(proc<0 || proc >= armci_nproc)
799
 
      return FAIL4;
800
 
 
801
 
    send.hndl = hndl;
802
 
    send.hlen = hlen;
803
 
    send.dlen = dlen;
804
 
    send.hdr = hdr;
805
 
    send.data = data;
806
 
 
807
 
    if(nb_handle){
808
 
      nb_handle->tag = GET_NEXT_NBTAG();
809
 
      nb_handle->op  = GET;
810
 
      nb_handle->proc= proc;
811
 
      nb_handle->bufid=NB_NONE;
812
 
    }
813
 
    else {
814
 
      ORDER(GET,proc); /*ensure ordering */      
815
 
      nb_handle = NULL;
816
 
    }  
817
 
 
818
 
#if defined(LAPI) || defined(GM) || defined(VAPI) || defined(QUADRICS)
819
 
    if(armci_rem_gpc(GET, darr, 2, &send, proc, 1, nb_handle))
820
 
#endif
821
 
      return FAIL2;
822
 
    return 0;
823
 
}
824
 
 
825
 
int armci_sameclusnode(int proc) {
826
 
  return SAMECLUSNODE(proc);
827
 
}
828
 
#endif
829
 
 
830
 
void _armci_init_handle(armci_hdl_t *hdl)
831
 
{
832
 
    ((double *)((hdl)->data))[0]=0;
833
 
    ((double *)((hdl)->data))[1]=0;
834
 
}
835
 
 
836
 
static inline int val_to_char(int v)
837
 
{
838
 
    if (v >= 0 && v < 10)
839
 
      return '0' + v;
840
 
    else if (v >= 10 && v < 16)
841
 
      return ('a' - 10) + v;
842
 
    else
843
 
      return -1;
844
 
}
845
 
static const char *nexttoken(const char *q, int sep)
846
 
{
847
 
    if (q)
848
 
      q = strchr(q, sep);
849
 
    if (q)
850
 
      q++;
851
 
    return q;
852
 
}
853
 
 
854
 
#ifdef PORTALS_UNRESOLVED
855
 
int cstr_to_cpuset(cpu_set_t * mask, const char *str)
856
 
{
857
 
const char     *p, *q;
858
 
q = str;
859
 
    CPU_ZERO(mask);
860
 
 
861
 
    while (p = q, q = nexttoken(q, ','), p) {
862
 
    unsigned int    a;  /* beginning of range */
863
 
    unsigned int    b;  /* end of range */
864
 
    unsigned int    s;  /* stride */
865
 
    const char     *c1, *c2;
866
 
      if (sscanf(p, "%u", &a) < 1)
867
 
        return 1;
868
 
      b = a;
869
 
      s = 1;
870
 
      c1 = nexttoken(p, '-');
871
 
      c2 = nexttoken(p, ',');
872
 
      if (c1 != NULL && (c2 == NULL || c1 < c2)) {
873
 
        if (sscanf(c1, "%u", &b) < 1)
874
 
          return 1;
875
 
        c1 = nexttoken(c1, ':');
876
 
        if (c1 != NULL && (c2 == NULL || c1 < c2))
877
 
          if (sscanf(c1, "%u", &s) < 1) {
878
 
            return 1;
879
 
          }
880
 
      }
881
 
      if (!(a <= b))
882
 
        return 1;
883
 
      while (a <= b) {
884
 
        CPU_SET(a, mask);
885
 
        a += s;
886
 
      }
887
 
    }
888
 
    return 0;
889
 
}
890
 
 
891
 
char *cpuset_to_cstr(cpu_set_t * mask, char *str)
892
 
{
893
 
int             i;
894
 
char           *ptr = str;
895
 
int             entry_made = 0;
896
 
    for (i = 0; i < CPU_SETSIZE; i++) {
897
 
      if (CPU_ISSET(i, mask)) {
898
 
      int             j;
899
 
      int             run = 0;
900
 
        entry_made = 1;
901
 
        for (j = i + 1; j < CPU_SETSIZE; j++) {
902
 
          if (CPU_ISSET(j, mask))
903
 
            run++;
904
 
          else
905
 
            break;
906
 
        }
907
 
        if (!run)
908
 
          sprintf(ptr, "%d,", i);
909
 
        else if (run == 1) {
910
 
          sprintf(ptr, "%d,%d,", i, i + 1);
911
 
          i++;
912
 
        } else {
913
 
          sprintf(ptr, "%d-%d,", i, i + run);
914
 
          i += run;
915
 
        }
916
 
        while (*ptr != 0)
917
 
          ptr++;
918
 
      }
919
 
    }
920
 
    ptr -= entry_made;
921
 
    *ptr = 0;
922
 
    return str;
923
 
}
924
 
 
925
 
char *cpuset_to_str(cpu_set_t * mask, char *str)
926
 
{
927
 
int             base;
928
 
char           *ptr = str;
929
 
char           *ret = 0;
930
 
    for (base = CPU_SETSIZE - 4; base >= 0; base -= 4) {
931
 
    char    val = 0;
932
 
      if (CPU_ISSET(base, mask))
933
 
        val |= 1;
934
 
      if (CPU_ISSET(base + 1, mask))
935
 
        val |= 2;
936
 
      if (CPU_ISSET(base + 2, mask))
937
 
        val |= 4;
938
 
      if (CPU_ISSET(base + 3, mask))
939
 
        val |= 8;
940
 
      if (!ret && val)
941
 
        ret = ptr;
942
 
      *ptr++ = val_to_char(val);
943
 
    }
944
 
    *ptr = 0;
945
 
    return ret ? ret : ptr - 1;
946
 
}
947
 
#endif
948
 
 
949
 
 
950
 
long armci_cksm_copy(char *src, char *dst, size_t bytes)
951
 
{
952
 
long sum = 0;
953
 
size_t count=bytes;
954
 
  while( count > 1 )  {
955
 
    sum += * (unsigned int *) src++;
956
 
    count -= 4;
957
 
  }
958
 
 
959
 
  if( count > 0 ){
960
 
          printf("\nblistering barnicles");
961
 
    sum += * (unsigned char *) src;
962
 
  }
963
 
 
964
 
  while (sum>>32)
965
 
    sum = (sum & 0xffffffff) + (sum >> 32);
966
 
  return(~sum);
967
 
}
968
 
 
969
 
void code_summary() {
970
 
  printf("\nActive #defines that could affect ARMCI");
971
 
  printf("\n----------------------------------------");
972
 
# ifdef ORNL_USE_DS_FOR_REMOTE_GETS
973
 
  printf("\n#define ORNL_USE_DS_FOR_REMOTE_GETS");
974
 
# endif
975
 
 
976
 
# ifdef PORTALS_USE_RENDEZ_VOUS
977
 
  printf("\n#define PORTALS_USE_RENDEZ_VOUS");
978
 
# endif  
979
 
 
980
 
# ifdef PORTALS_LIMIT_REMOTE_REQUESTS_BY_NODE
981
 
  printf("\n#define PORTALS_LIMIT_REMOTE_REQUESTS_BY_NODE");
982
 
# endif
983
 
 
984
 
# ifdef PORTALS_AFFINITY
985
 
  printf("\n#define PORTALS_AFFINITY");
986
 
# endif
987
 
 
988
 
/* 
989
 
# ifdef CRAY_USE_MDMD_COPY
990
 
  printf("\n#define CRAY_USE_MDMD_COPY");
991
 
# endif
992
 
*/
993
 
  printf("\n----------------------------------------");
994
 
  printf("\nInfo @ armci/src/code_options.h");
995
 
  printf("\n----------------------------------------\n");
996
 
 
997
 
# ifdef PORTALS
998
 
  portals_print_summary();
999
 
# endif
1000
 
}