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

« back to all changes in this revision

Viewing changes to src/tools/ga-5-2/armci/src-portals/portals.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
   portals.c  -- wrapper for commonly used portals calls
 
6
   author: ryan olson
 
7
   email:  ryan@cray.com
 
8
\* ---------------------------------------------------------------------------------------------- */
 
9
#include <stdio.h>
 
10
#include "armcip.h"
 
11
 
 
12
/* ---------------------------------------------------------------------------------------------- *\
 
13
   global variables
 
14
\* ---------------------------------------------------------------------------------------------- */
 
15
   ptl_process_id_t *portals_id_map = NULL;
 
16
   ptl_process_id_t *portals_cloned_id_map = NULL;
 
17
 
 
18
   size_t portalsMaxEagerMessageSize;
 
19
 
 
20
   MPI_Comm portals_smp_comm;
 
21
 
 
22
/* ---------------------------------------------------------------------------------------------- *\
 
23
   static variables for this object
 
24
\* ---------------------------------------------------------------------------------------------- */
 
25
   static int portals_verbose = 0;
 
26
 
 
27
 
 
28
/* ---------------------------------------------------------------------------------------------- *\
 
29
   portals wrappers
 
30
\* ---------------------------------------------------------------------------------------------- */
 
31
 
 
32
 
 
33
int
 
34
portals_init(ptl_handle_ni_t *nih)
 
35
{
 
36
        int num_interfaces = 0;
 
37
        int rc;
 
38
 
 
39
        rc = PtlInit(&num_interfaces);
 
40
        if (rc != PTL_OK) {
 
41
                printf("PtlInit err %d\n", rc);
 
42
                return rc;
 
43
        }
 
44
 
 
45
        rc = PtlNIInit(CRAY_UK_SSNAL, PTL_PID_ANY, NULL, NULL, nih);
 
46
        if (rc != PTL_OK && rc != PTL_IFACE_DUP) {
 
47
                printf("PtlNIInit err %d\n", rc);
 
48
                return rc;
 
49
        }
 
50
 
 
51
        portalsMaxEagerMessageSize = PORTALS_MAX_EAGER_MESSAGE_SIZE;
 
52
 
 
53
        return PTL_OK;
 
54
}
 
55
 
 
56
 
 
57
int
 
58
portals_finalize(ptl_handle_ni_t nih)
 
59
{
 
60
        PtlNIFini(nih);
 
61
        PtlFini();
 
62
        return PTL_OK;
 
63
}
 
64
 
 
65
 
 
66
int
 
67
portals_getid(ptl_handle_ni_t nih, ptl_process_id_t *id)
 
68
{
 
69
        int rc;
 
70
 
 
71
        rc = PtlGetId(nih, id);
 
72
        if(rc != PTL_OK) {
 
73
                printf("PtlGetId err %d\n",rc);
 
74
                return rc;
 
75
        }
 
76
 
 
77
        return PTL_OK;
 
78
}
 
79
 
 
80
 
 
81
int
 
82
portals_create_eq(ptl_handle_ni_t nih, ptl_size_t count, ptl_handle_eq_t *eq_handle) 
 
83
{
 
84
        int rc;
 
85
 
 
86
        rc = PtlEQAlloc(nih, count, PTL_EQ_HANDLER_NONE, eq_handle);
 
87
        if (rc != PTL_OK) {
 
88
                printf("PtlEQAlloc err %d\n", rc);
 
89
                return rc;
 
90
        }
 
91
 
 
92
        return PTL_OK;
 
93
}
 
94
 
 
95
 
 
96
int
 
97
portals_free_eq(ptl_handle_eq_t eq)
 
98
{
 
99
        int rc;
 
100
 
 
101
        rc = PtlEQFree(eq);
 
102
        if (rc != PTL_OK) {
 
103
                printf("PtlEQFree err %d\n",rc);
 
104
                return rc;
 
105
        }
 
106
 
 
107
        return PTL_OK;
 
108
}
 
109
 
 
110
/* 
 
111
   permanent buffers - such as unexpected receive buffers or data requests
 
112
   buffers should not be unlinked.  client side buffers, such as large puts/accs
 
113
   would create a ME in front of the MATCH ALL unexpected buffer/data req ME. 
 
114
   on the client side, the MATCH ALL ME should catch the ACKs 
 
115
*/
 
116
 
 
117
 
 
118
int
 
119
portals_me_attach(ptl_handle_ni_t  nih,
 
120
                  ptl_process_id_t match_id,
 
121
                  ptl_match_bits_t match_bits,
 
122
                  ptl_match_bits_t ignore_bits,
 
123
                  ptl_handle_me_t *me_handle)
 
124
{
 
125
        int rc = PtlMEAttach(nih,PORTALS_INDEX,match_id,match_bits,ignore_bits,
 
126
                             PTL_UNLINK,PTL_INS_BEFORE,me_handle);
 
127
        if (rc != PTL_OK) {
 
128
                printf("PtlAttach err %d in me_attach\n",rc);
 
129
                return rc;
 
130
        }
 
131
 
 
132
        return PTL_OK;
 
133
}
 
134
 
 
135
int
 
136
portals_me_insert(ptl_handle_me_t  base,
 
137
                  ptl_process_id_t pe_match_id, 
 
138
                  ptl_match_bits_t match_bits,
 
139
                  ptl_match_bits_t ignore_bits,
 
140
                  ptl_handle_me_t *me_handle)
 
141
{
 
142
        int rc = PtlMEInsert(base,pe_match_id,match_bits,ignore_bits,
 
143
                             PTL_UNLINK,PTL_INS_BEFORE,me_handle);
 
144
        if (rc != PTL_OK) {
 
145
                printf("PtlME err %d in portals_push_me\n",rc);
 
146
                return rc;
 
147
        }
 
148
 
 
149
        return rc;
 
150
}
 
151
 
 
152
 
 
153
int
 
154
portals_me_unlink(ptl_handle_me_t meh)
 
155
{
 
156
        int rc = PtlMEUnlink(meh);
 
157
 
 
158
        if(rc != PTL_OK) {
 
159
           printf("PtlMEUnlink err %d in me_unlink\n",rc);
 
160
        }
 
161
 
 
162
        return rc;
 
163
}
 
164
 
 
165
 
 
166
int
 
167
portals_md_attach(ptl_handle_me_t me_handle,
 
168
                  ptl_md_t md,
 
169
                  ptl_unlink_t unlink_op,
 
170
                  ptl_handle_md_t *md_handle)
 
171
{
 
172
        int rc = PtlMDAttach(me_handle, md, unlink_op, md_handle);
 
173
        if (rc != PTL_OK) {
 
174
                printf("PtlMDAttach err %d\n",rc);
 
175
                return rc;
 
176
        }
 
177
 
 
178
        return PTL_OK;
 
179
}
 
180
 
 
181
 
 
182
int 
 
183
portals_md_bind(ptl_handle_ni_t nih,
 
184
                ptl_md_t md,
 
185
                ptl_unlink_t unlink_op,
 
186
                ptl_handle_md_t *md_handle)
 
187
{
 
188
        int rc = PtlMDBind(nih, md, unlink_op, md_handle);
 
189
        if (rc != PTL_OK) {
 
190
                printf("PtlMDBind err %d\n",rc);
 
191
                return rc;
 
192
        }
 
193
 
 
194
        return rc;
 
195
}
 
196
 
 
197
 
 
198
int
 
199
portals_eqwait(ptl_handle_eq_t eqh, ptl_event_t *ev) 
 
200
{
 
201
        int rc = PtlEQWait(eqh, ev);
 
202
        if (rc != PTL_OK) {
 
203
                printf("PtlEQWait err %d\n",rc);
 
204
                return rc;
 
205
        }
 
206
 
 
207
        return  PTL_OK;
 
208
}
 
209
 
 
210
 
 
211
static int
 
212
notify(portals_desc_t *desc, int state, char *name) {
 
213
        if(desc->state & state) {
 
214
                desc->state &= ~state;
 
215
                if(desc->state == 0) desc->done = 1;
 
216
                return 1;
 
217
        } else {
 
218
                printf("event: %s with desc state %x not %x\n",name,desc->state,state);
 
219
                abort();
 
220
                return 0;
 
221
        }
 
222
}
 
223
 
 
224
 
 
225
int
 
226
portals_wait(portals_desc_t *wait_on_desc) {
 
227
 
 
228
        int rc;
 
229
        ptl_event_t ev;
 
230
        portals_desc_t *desc = NULL;
 
231
 
 
232
        while(wait_on_desc->state) {
 
233
 
 
234
                rc = portals_eqwait(wait_on_desc->eqh, &ev);
 
235
                if (rc != PTL_OK) {
 
236
                        printf("eq wait error in portals_wait\n");
 
237
                        abort();
 
238
                }
 
239
                
 
240
                desc = (portals_desc_t *) ev.md.user_ptr;
 
241
 
 
242
                switch(ev.type) {
 
243
 
 
244
                case PTL_EVENT_SEND_START:
 
245
                         if (portals_verbose) printf("%s event: send start\n",Portals_ID());
 
246
                         notify(desc, STATE_SEND_START, "send start");
 
247
                         break;
 
248
 
 
249
                case PTL_EVENT_SEND_END:
 
250
                         if (portals_verbose) printf("%s event: send end\n",Portals_ID());
 
251
                         notify(desc, STATE_SEND_END, "send end");
 
252
                         break;
 
253
 
 
254
                case PTL_EVENT_REPLY_START:
 
255
                         if (portals_verbose) printf("%s event: reply start\n",Portals_ID());
 
256
                         notify(desc, STATE_REPLY_START, "reply start");
 
257
                         break;
 
258
 
 
259
                case PTL_EVENT_REPLY_END:
 
260
                         if (portals_verbose) printf("%s event: reply end\n",Portals_ID());
 
261
                         notify(desc, STATE_REPLY_END, "reply end");
 
262
                         break;
 
263
 
 
264
                case PTL_EVENT_ACK:
 
265
                         if (portals_verbose) printf("%s event: ack\n",Portals_ID());
 
266
                         printf("%s event ack: md.threshold=%d\n",Portals_ID(),ev.md.threshold);
 
267
                         notify(desc, STATE_ACK, "ack");
 
268
                         break;
 
269
 
 
270
                case PTL_EVENT_PUT_START:
 
271
                         if (portals_verbose) printf("%s event: put start\n",Portals_ID());
 
272
                         notify(desc, STATE_PUT_START, "put start");
 
273
                         break;
 
274
 
 
275
                case PTL_EVENT_PUT_END:
 
276
                         if (portals_verbose) printf("%s event: put end\n",Portals_ID());
 
277
                         if (notify(desc, STATE_PUT_END, "put end")) {
 
278
                         //      desc->len = ev.mlength;
 
279
                         //      desc->off = ev.offset;
 
280
                         }
 
281
                         break;
 
282
 
 
283
                case PTL_EVENT_GET_START:
 
284
                        if (portals_verbose) printf("%s event: get start\n",Portals_ID());
 
285
                        notify(desc, STATE_GET_START, "get start");
 
286
                        break;
 
287
 
 
288
                case PTL_EVENT_GET_END:
 
289
                        if (portals_verbose) printf("%s event: get end\n",Portals_ID());
 
290
                        notify(desc, STATE_GET_END, "get end");
 
291
                        break;
 
292
 
 
293
                case PTL_EVENT_UNLINK:
 
294
                        if (portals_verbose) printf("%s event: unlink\n",Portals_ID());
 
295
                        notify(desc, STATE_UNLINK, "unlink");
 
296
                        break;
 
297
 
 
298
                default:
 
299
                        printf("%s event: %d\n",Portals_ID(), ev.type);
 
300
                        break;
 
301
                }
 
302
 
 
303
        }
 
304
 
 
305
        return PTL_OK;
 
306
}
 
307
 
 
308
 
 
309
int
 
310
portals_put(portals_desc_t *desc)
 
311
{
 
312
        int rc;
 
313
        int threshold = 1;
 
314
        ptl_md_t md = { 0 };
 
315
        ptl_handle_md_t md_handle;
 
316
        ptl_ack_req_t ack_req = PTL_NOACK_REQ; 
 
317
 
 
318
      # ifdef PORTALS_PUT_USE_ACK
 
319
        ack_req = PTL_ACK_REQ;
 
320
        threshold++;
 
321
      # endif
 
322
 
 
323
        md.start     = desc->buffer;
 
324
        md.length    = desc->length;
 
325
        md.threshold = threshold;
 
326
        md.options   = 0;
 
327
      # ifndef PORTALS_PUT_USE_START
 
328
        md.options  |= PTL_MD_EVENT_START_DISABLE;
 
329
      # endif
 
330
        md.user_ptr  = desc;
 
331
        md.eq_handle = desc->eqh;
 
332
 
 
333
        rc = portals_md_bind(desc->nih, md, PTL_UNLINK, &md_handle);
 
334
        if (rc != PTL_OK) {
 
335
                printf("failed to bind local md in put; err %d",rc);
 
336
                Fatal_error(rc);
 
337
        }
 
338
 
 
339
        rc = PtlPut(md_handle,
 
340
                    ack_req,
 
341
                    desc->id,
 
342
                    PORTALS_INDEX,
 
343
                    0,
 
344
                    desc->mbits,
 
345
                    0,
 
346
                    desc->hdr);
 
347
        if (rc != PTL_OK) {
 
348
                printf("PtlPut err %d\n",rc);
 
349
                return rc;
 
350
        }
 
351
 
 
352
        desc->done  = 0;
 
353
        desc->state = STATE_SEND_END;
 
354
 
 
355
      # ifdef PORTALS_PUT_USE_START
 
356
        desc->state |= STATE_SEND_START;
 
357
      # endif
 
358
 
 
359
      # ifdef PORTALS_PUT_USE_ACK
 
360
        desc->state |= STATE_ACK;
 
361
      # endif
 
362
 
 
363
        return PTL_OK;
 
364
}
 
365
 
 
366
 
 
367
int
 
368
portals_get(portals_desc_t* desc)
 
369
{
 
370
        int rc;
 
371
        ptl_md_t md = { 0 };
 
372
        ptl_handle_md_t md_handle;
 
373
 
 
374
        md.start     = desc->buffer;
 
375
        md.length    = desc->length;
 
376
        md.threshold = 2;
 
377
        md.options   = 0;
 
378
      # ifndef PORTALS_GET_USE_START
 
379
        md.options  |= PTL_MD_EVENT_START_DISABLE;
 
380
      # endif
 
381
        md.user_ptr  = desc;
 
382
        md.eq_handle = desc->eqh;
 
383
 
 
384
        rc = portals_md_bind(desc->nih, md, PTL_UNLINK, &md_handle);
 
385
        if (rc != PTL_OK) {
 
386
                printf("failed to bind local md in get; err %d\n",rc);
 
387
                Fatal_error(rc);
 
388
        }
 
389
 
 
390
        rc = PtlGet(md_handle,
 
391
                    desc->id,
 
392
                    PORTALS_INDEX,
 
393
                    0,
 
394
                    desc->mbits,
 
395
                    0);
 
396
        if (rc != PTL_OK) {
 
397
                printf("PtlGet err %d\n",rc);
 
398
                Fatal_error(rc);
 
399
        }
 
400
 
 
401
        desc->done  = 0;
 
402
        desc->state = STATE_REPLY_END | STATE_SEND_END;
 
403
 
 
404
      # ifdef PORTALS_GET_USE_START
 
405
        desc->state |= STATE_REPLY_START;
 
406
      # endif
 
407
 
 
408
        return PTL_OK;
 
409
}
 
410
 
 
411
 
 
412
/*
 
413
portals_desc_t*
 
414
portals_get_free_desc(void)
 
415
{
 
416
        int i,rc;
 
417
        portals_desc_t *desc = NULL;
 
418
 
 
419
        while(desc == NULL) {
 
420
           for(i=0; i<PORTALS_MAX_DESCRIPTORS; i++) {
 
421
              if(portals_desc_list[i].done) {
 
422
                 desc = &portals_desc_list[i];
 
423
                 break;
 
424
              }
 
425
           }
 
426
           if(desc) break;
 
427
           portals_wait_any(&portals_desc_list,PORTALS_MAX_DESCRIPTORS);
 
428
        }
 
429
 
 
430
        bzero(desc,sizeof(portals_desc_t));
 
431
        return desc;
 
432
}
 
433
*/
 
434
 
 
435
void * 
 
436
portalsCloneDataServer( void * (*func)(void *) )
 
437
{
 
438
      char *stack = malloc(256*ONE_KB);
 
439
      char *stack_top = &stack[256*ONE_KB-1];
 
440
      pid_t pid = clone(func, (void *) stack_top,
 
441
                        CLONE_THREAD|CLONE_SIGHAND|CLONE_VM, NULL);
 
442
 
 
443
      if(pid == -1) {
 
444
         printf("clone failed in systemCreateClone\n");
 
445
         Fatal_error(911);
 
446
      }
 
447
 
 
448
      // data_server_pid = pid;
 
449
      return;
 
450
}
 
451
 
 
452
 
 
453
void
 
454
portalsSpinLockOnInt(volatile int *ptr, int val, int maxspin)
 
455
{
 
456
        int count = 0;
 
457
        extern void cpu_yield();
 
458
 
 
459
        while(*ptr != val) {
 
460
 
 
461
           if(++count < maxspin);
 
462
           else{
 
463
//             cpu_yield();
 
464
               count =0;
 
465
             # if defined(MACOSX) && defined(__ppc__) && defined(__GNUC__)
 
466
               __asm__ __volatile__ ("sync" ::: "memory");
 
467
             # endif
 
468
               __asm__ __volatile__ ("mfence" ::: "memory");
 
469
               __asm__ __volatile__ ("sfence" ::: "memory");
 
470
            }
 
471
        }
 
472
}
 
473
 
 
474
 
 
475
void Fatal_error(int rc) {
 
476
        armci_die("rmo fatal error",rc);
 
477
}
 
478
 
 
479
const char *Portals_ID() {
 
480
        static char string[128];
 
481
        sprintf(string,"[%i]:",armci_me);
 
482
        return string;
 
483
}
 
484
 
 
485
 
 
486
void
 
487
hex_print(const char* data, int length)
 
488
{
 
489
        int ptr = 0;
 
490
        for(;ptr < length;ptr++)
 
491
        {
 
492
                printf("0x%02x ",(unsigned char)*(data+ptr));
 
493
        }
 
494
        printf("\n");
 
495
}
 
496
 
 
497
void
 
498
bit_print(const char* data, int length)
 
499
{
 
500
        unsigned char mask = 0x01;
 
501
        int ptr = 0;
 
502
        int bit = 0;
 
503
        for(;ptr < length;ptr++)
 
504
        {
 
505
                for(bit = 7;bit >= 0;bit--)
 
506
                {
 
507
                        if ((mask << bit) & (unsigned char)*(data+ptr))
 
508
                        {
 
509
                                printf("1");
 
510
                        }
 
511
                        else
 
512
                        {
 
513
                                printf("0");
 
514
                        }
 
515
                }
 
516
                printf(" ");
 
517
        }
 
518
        printf("\n");
 
519
}
 
520
 
 
521
 
 
522
void
 
523
portals_print_summary()
 
524
{
 
525
        printf("PORTALS_MAX_DESCRIPTORS        = %d\n",PORTALS_MAX_DESCRIPTORS);
 
526
        printf("PORTALS_MAX_BUFS               = %d\n",PORTALS_MAX_BUFS);
 
527
        printf("PORTALS_MAX_SMALL_BUFS         = %d\n",PORTALS_MAX_SMALL_BUFS);
 
528
        printf("PORTALS_BUF_SIZE               = %d\n",PORTALS_BUF_SIZE);
 
529
        printf("PORTALS_SMALL_BUF_SIZE         = %d\n",PORTALS_SMALL_BUF_SIZE);
 
530
        printf("PORTALS_NREQUEST_BUFFERS       = %d\n",PORTALS_NREQUEST_BUFFERS);
 
531
        printf("PORTALS_MAX_EAGER_MESSAGE_SIZE = %d\n",PORTALS_MAX_EAGER_MESSAGE_SIZE);
 
532
        return;
 
533
}