4
/* ---------------------------------------------------------------------------------------------- *\
5
portals.c -- wrapper for commonly used portals calls
8
\* ---------------------------------------------------------------------------------------------- */
12
/* ---------------------------------------------------------------------------------------------- *\
14
\* ---------------------------------------------------------------------------------------------- */
15
ptl_process_id_t *portals_id_map = NULL;
16
ptl_process_id_t *portals_cloned_id_map = NULL;
18
size_t portalsMaxEagerMessageSize;
20
MPI_Comm portals_smp_comm;
22
/* ---------------------------------------------------------------------------------------------- *\
23
static variables for this object
24
\* ---------------------------------------------------------------------------------------------- */
25
static int portals_verbose = 0;
28
/* ---------------------------------------------------------------------------------------------- *\
30
\* ---------------------------------------------------------------------------------------------- */
34
portals_init(ptl_handle_ni_t *nih)
36
int num_interfaces = 0;
39
rc = PtlInit(&num_interfaces);
41
printf("PtlInit err %d\n", rc);
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);
51
portalsMaxEagerMessageSize = PORTALS_MAX_EAGER_MESSAGE_SIZE;
58
portals_finalize(ptl_handle_ni_t nih)
67
portals_getid(ptl_handle_ni_t nih, ptl_process_id_t *id)
71
rc = PtlGetId(nih, id);
73
printf("PtlGetId err %d\n",rc);
82
portals_create_eq(ptl_handle_ni_t nih, ptl_size_t count, ptl_handle_eq_t *eq_handle)
86
rc = PtlEQAlloc(nih, count, PTL_EQ_HANDLER_NONE, eq_handle);
88
printf("PtlEQAlloc err %d\n", rc);
97
portals_free_eq(ptl_handle_eq_t eq)
103
printf("PtlEQFree err %d\n",rc);
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
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)
125
int rc = PtlMEAttach(nih,PORTALS_INDEX,match_id,match_bits,ignore_bits,
126
PTL_UNLINK,PTL_INS_BEFORE,me_handle);
128
printf("PtlAttach err %d in me_attach\n",rc);
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)
142
int rc = PtlMEInsert(base,pe_match_id,match_bits,ignore_bits,
143
PTL_UNLINK,PTL_INS_BEFORE,me_handle);
145
printf("PtlME err %d in portals_push_me\n",rc);
154
portals_me_unlink(ptl_handle_me_t meh)
156
int rc = PtlMEUnlink(meh);
159
printf("PtlMEUnlink err %d in me_unlink\n",rc);
167
portals_md_attach(ptl_handle_me_t me_handle,
169
ptl_unlink_t unlink_op,
170
ptl_handle_md_t *md_handle)
172
int rc = PtlMDAttach(me_handle, md, unlink_op, md_handle);
174
printf("PtlMDAttach err %d\n",rc);
183
portals_md_bind(ptl_handle_ni_t nih,
185
ptl_unlink_t unlink_op,
186
ptl_handle_md_t *md_handle)
188
int rc = PtlMDBind(nih, md, unlink_op, md_handle);
190
printf("PtlMDBind err %d\n",rc);
199
portals_eqwait(ptl_handle_eq_t eqh, ptl_event_t *ev)
201
int rc = PtlEQWait(eqh, ev);
203
printf("PtlEQWait err %d\n",rc);
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;
218
printf("event: %s with desc state %x not %x\n",name,desc->state,state);
226
portals_wait(portals_desc_t *wait_on_desc) {
230
portals_desc_t *desc = NULL;
232
while(wait_on_desc->state) {
234
rc = portals_eqwait(wait_on_desc->eqh, &ev);
236
printf("eq wait error in portals_wait\n");
240
desc = (portals_desc_t *) ev.md.user_ptr;
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");
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");
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");
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");
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");
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");
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;
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");
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");
293
case PTL_EVENT_UNLINK:
294
if (portals_verbose) printf("%s event: unlink\n",Portals_ID());
295
notify(desc, STATE_UNLINK, "unlink");
299
printf("%s event: %d\n",Portals_ID(), ev.type);
310
portals_put(portals_desc_t *desc)
315
ptl_handle_md_t md_handle;
316
ptl_ack_req_t ack_req = PTL_NOACK_REQ;
318
# ifdef PORTALS_PUT_USE_ACK
319
ack_req = PTL_ACK_REQ;
323
md.start = desc->buffer;
324
md.length = desc->length;
325
md.threshold = threshold;
327
# ifndef PORTALS_PUT_USE_START
328
md.options |= PTL_MD_EVENT_START_DISABLE;
331
md.eq_handle = desc->eqh;
333
rc = portals_md_bind(desc->nih, md, PTL_UNLINK, &md_handle);
335
printf("failed to bind local md in put; err %d",rc);
339
rc = PtlPut(md_handle,
348
printf("PtlPut err %d\n",rc);
353
desc->state = STATE_SEND_END;
355
# ifdef PORTALS_PUT_USE_START
356
desc->state |= STATE_SEND_START;
359
# ifdef PORTALS_PUT_USE_ACK
360
desc->state |= STATE_ACK;
368
portals_get(portals_desc_t* desc)
372
ptl_handle_md_t md_handle;
374
md.start = desc->buffer;
375
md.length = desc->length;
378
# ifndef PORTALS_GET_USE_START
379
md.options |= PTL_MD_EVENT_START_DISABLE;
382
md.eq_handle = desc->eqh;
384
rc = portals_md_bind(desc->nih, md, PTL_UNLINK, &md_handle);
386
printf("failed to bind local md in get; err %d\n",rc);
390
rc = PtlGet(md_handle,
397
printf("PtlGet err %d\n",rc);
402
desc->state = STATE_REPLY_END | STATE_SEND_END;
404
# ifdef PORTALS_GET_USE_START
405
desc->state |= STATE_REPLY_START;
414
portals_get_free_desc(void)
417
portals_desc_t *desc = NULL;
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];
427
portals_wait_any(&portals_desc_list,PORTALS_MAX_DESCRIPTORS);
430
bzero(desc,sizeof(portals_desc_t));
436
portalsCloneDataServer( void * (*func)(void *) )
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);
444
printf("clone failed in systemCreateClone\n");
448
// data_server_pid = pid;
454
portalsSpinLockOnInt(volatile int *ptr, int val, int maxspin)
457
extern void cpu_yield();
461
if(++count < maxspin);
465
# if defined(MACOSX) && defined(__ppc__) && defined(__GNUC__)
466
__asm__ __volatile__ ("sync" ::: "memory");
468
__asm__ __volatile__ ("mfence" ::: "memory");
469
__asm__ __volatile__ ("sfence" ::: "memory");
475
void Fatal_error(int rc) {
476
armci_die("rmo fatal error",rc);
479
const char *Portals_ID() {
480
static char string[128];
481
sprintf(string,"[%i]:",armci_me);
487
hex_print(const char* data, int length)
490
for(;ptr < length;ptr++)
492
printf("0x%02x ",(unsigned char)*(data+ptr));
498
bit_print(const char* data, int length)
500
unsigned char mask = 0x01;
503
for(;ptr < length;ptr++)
505
for(bit = 7;bit >= 0;bit--)
507
if ((mask << bit) & (unsigned char)*(data+ptr))
523
portals_print_summary()
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);