root/mpich2/trunk/src/mpid/ch3/channels/nemesis/nemesis/netmod/newmad/newmad_init.c @ 4774

Revision 4774, 16.5 KB (checked in by mercierg, 5 months ago)

Fixed init for Newmad when using PIOMan

Line 
1/* -*- Mode: C; c-basic-offset:4 ; -*- */
2/*
3 *  (C) 2006 by Argonne National Laboratory.
4 *      See COPYRIGHT in top-level directory.
5 */
6
7#include "mpid_nem_impl.h"
8#include "newmad_impl.h"
9
10#define MPIDI_CH3I_HOSTNAME_KEY  "hostname_id"
11
12MPID_nem_netmod_funcs_t MPIDI_nem_newmad_funcs = {
13    MPID_nem_newmad_init,
14    MPID_nem_newmad_finalize,
15    MPID_nem_newmad_ckpt_shutdown,
16    MPID_nem_newmad_poll,
17    MPID_nem_newmad_send,
18    MPID_nem_newmad_get_business_card,
19    MPID_nem_newmad_connect_to_root,
20    MPID_nem_newmad_vc_init,
21    MPID_nem_newmad_vc_destroy,
22    MPID_nem_newmad_vc_terminate
23};
24
25static MPIDI_Comm_ops_t comm_ops = {
26    MPID_nem_newmad_directRecv, /* recv_posted */
27
28    MPID_nem_newmad_directSend, /* send */
29    MPID_nem_newmad_directSend, /* rsend */
30    MPID_nem_newmad_directSsend, /* ssend */
31    MPID_nem_newmad_directSend, /* isend */
32    MPID_nem_newmad_directSend, /* irsend */
33    MPID_nem_newmad_directSsend, /* issend */
34
35    NULL,                   /* send_init */
36    NULL,                   /* bsend_init */
37    NULL,                   /* rsend_init */
38    NULL,                   /* ssend_init */
39    NULL,                   /* startall */
40
41    MPID_nem_newmad_cancel_send,/* cancel_send */
42    MPID_nem_newmad_cancel_recv, /* cancel_recv */
43
44    MPID_nem_newmad_probe, /* probe */
45    MPID_nem_newmad_iprobe /* iprobe */
46};
47
48
49static int         mpid_nem_newmad_myrank;
50static int         num_recv_req = 0;
51static int         num_send_req = 0;
52static MPID_nem_newmad_init_req_t *init_reqs = NULL;
53static nm_drv_id_t drv_id[MPID_NEM_NMAD_MAX_NETS];
54static char       *url[MPID_NEM_NMAD_MAX_NETS];
55static char        url_keys[MPID_NEM_NMAD_MAX_NETS][MPID_NEM_NMAD_MAX_SIZE] = {"url_id0","url_id1","url_id2","url_id3"};
56static int         mpid_nem_newmad_num_rails = 1 ;
57nm_core_t          mpid_nem_newmad_pcore;
58int                mpid_nem_newmad_pending_send_req = 0;
59
60#ifdef MPID_MAD_MODULE_MULTIRAIL
61static puk_component_t *p_driver_load_array;
62static void mpid_nem_newmad_rails(void)
63{
64    int index = 0;
65    mpid_nem_newmad_num_rails = 0 ;
66#if defined CONFIG_IBVERBS
67    mpid_nem_newmad_num_rails++;
68#endif
69#if defined CONFIG_MX
70    mpid_nem_newmad_num_rails++;
71#endif
72#if defined CONFIG_GM
73    mpid_nem_newmad_num_rails++;
74#endif
75#if defined CONFIG_QSNET
76    mpid_nem_newmad_num_rails++;
77#endif
78#if defined CONFIG_TCP
79    mpid_nem_newmad_num_rails++;
80#endif
81    MPIU_Assert(mpid_nem_newmad_num_rails <= MPID_NEM_NMAD_MAX_NETS);
82
83    p_driver_load_array = (puk_component_t *)MPIU_Malloc( mpid_nem_newmad_num_rails*sizeof(puk_component_t));
84
85#if defined CONFIG_IBVERBS
86    p_driver_load_array[index++] = nm_core_component_load("driver", "ibverbs");
87#endif
88#if defined CONFIG_MX
89    p_driver_load_array[index++] = nm_core_component_load("driver", "mx");
90#endif
91#if defined CONFIG_GM
92    p_driver_load_array[index++] = nm_core_component_load("driver", "gm");
93#endif
94#if defined CONFIG_QSNET
95    p_driver_load_array[index++] = nm_core_component_load("driver", "qsnet");
96#endif
97#if defined CONFIG_TCP
98    p_driver_load_array[index++] = nm_core_component_load("driver", "tcp");
99#endif
100}
101#else /* MPID_MAD_MODULE_MULTIRAIL */
102static puk_component_t  p_driver_load;
103static void mpid_nem_newmad_rails(void)
104{
105# if defined CONFIG_IBVERBS
106    p_driver_load = nm_core_component_load("driver", "ibverbs");
107# elif defined CONFIG_MX
108    p_driver_load = nm_core_component_load("driver", "mx");
109# elif defined CONFIG_GM
110    p_driver_load = nm_core_component_load("driver", "gm");
111# elif defined CONFIG_QSNET
112    p_driver_load = nm_core_component_load("driver", "qsnet");
113# elif defined CONFIG_TCP
114    p_driver_load = nm_core_component_load("driver", "tcp");
115# endif
116}
117#endif /* MULTIRAIL */
118
119
120#undef FUNCNAME
121#define FUNCNAME init_mad
122#undef FCNAME
123#define FCNAME MPIDI_QUOTE(FUNCNAME)
124static int init_mad( MPIDI_PG_t *pg_p )
125{
126#if 0
127#ifdef CONFIG_TCP
128#ifndef MPID_MAD_MODULE_MULTIRAIL
129    char  hostname[16];
130#endif /* TCP */
131#endif /* MPID_MAD_MODULE_MULTIRAIL */
132#endif
133    int   index = 0;
134    int   ret;
135    int   mpi_errno = MPI_SUCCESS;
136    char *dummy_argv[1] = {NULL};
137    int   dummy_argc    = 1;
138   
139    ret = nm_core_init(&dummy_argc,dummy_argv, &mpid_nem_newmad_pcore);
140    if (ret != NM_ESUCCESS){
141        fprintf(stdout,"nm_core_init returned err = %d\n", ret);
142    }
143
144    mpid_nem_newmad_rails();
145#ifdef MPID_MAD_MODULE_MULTIRAIL
146    fprintf(stdout,"Number of rails : %i\n",nem_mad_num_rail);
147#endif /* MPID_MAD_MODULE_MULTIRAIL */
148
149    ret = nm_sr_init(mpid_nem_newmad_pcore);
150    if(ret != NM_ESUCCESS) {
151        fprintf(stdout,"nm_so_pack_interface_init return err = %d\n", ret);
152    }
153#ifdef MPID_MAD_MODULE_MULTIRAIL
154#warning "========== MAD MODULE MULTIRAIL CODE ENABLED ============="
155    ret = nm_core_driver_load_init_some(mpid_nem_newmad_pcore, mpid_nem_newmad_num_rails, 
156                                        p_driver_load_array, drv_id, url);
157#else /* MPID_MAD_MODULE_MULTIRAIL */
158    ret = nm_core_driver_load_init(mpid_nem_newmad_pcore, 
159                                   p_driver_load, &drv_id[0], &url[0]);
160#endif /* MPID_MAD_MODULE_MULTIRAIL */
161    if (ret != NM_ESUCCESS) {
162        fprintf(stdout,"nm_core_driver_init(some) returned ret = %d\n", ret);
163    }
164   
165#if 0
166#ifdef CONFIG_TCP
167#ifndef MPID_MAD_MODULE_MULTIRAIL
168    {
169        gethostname(hostname, 16);
170        strcat(hostname,":");
171        strcat(hostname,url[0]);
172        url[0] = (char *)MPIU_Malloc(strlen(hostname)+1);
173        strcpy(url[0],hostname);
174    }
175#endif /* !MULTIRAIL  */
176#endif /* TCP */                                                                                                                         
177#endif 
178   
179   nm_ns_init(mpid_nem_newmad_pcore);
180   
181   init_reqs = (MPID_nem_newmad_init_req_t *)MPIU_Malloc(MPID_nem_mem_region.num_procs*sizeof(MPID_nem_newmad_init_req_t));
182   for (index = 0; index < MPID_nem_mem_region.num_procs ; index ++)
183   {
184      memset(init_reqs + index,0,sizeof(MPID_nem_newmad_init_req_t));
185      init_reqs[index].process_no  = -2;
186     
187      if ( !(MPID_NEM_IS_LOCAL(index)) && (index > mpid_nem_newmad_myrank))
188        num_recv_req++;
189      else if ( !(MPID_NEM_IS_LOCAL(index)) && (index < mpid_nem_newmad_myrank))
190        num_send_req++;
191   }
192   
193 fn_exit:
194    return mpi_errno;
195 fn_fail: ATTRIBUTE((unused))
196    goto fn_exit;
197}
198
199
200
201/*
202 int 
203   MPID_nem_newmad_init(MPID_nem_queue_ptr_t proc_recv_queue, MPID_nem_queue_ptr_t proc_free_queue, MPID_nem_cell_ptr_t proc_elements, int num_proc_elements,
204                  MPID_nem_cell_ptr_t module_elements, int num_module_elements,
205                  MPID_nem_queue_ptr_t *module_free_queue)
206
207   IN
208       proc_recv_queue -- main recv queue for the process
209       proc_free_queue -- main free queueu for the process
210       proc_elements -- pointer to the process' queue elements
211       num_proc_elements -- number of process' queue elements
212       module_elements -- pointer to queue elements to be used by this module
213       num_module_elements -- number of queue elements for this module
214       ckpt_restart -- true if this is a restart from a checkpoint.  In a restart, the network needs to be brought up again, but
215                       we want to keep things like sequence numbers.
216   OUT
217       free_queue -- pointer to the free queue for this module.  The process will return elements to
218                     this queue
219*/
220
221#undef FUNCNAME
222#define FUNCNAME MPID_nem_newmad_init
223#undef FCNAME
224#define FCNAME MPIDI_QUOTE(FUNCNAME)
225int
226MPID_nem_newmad_init (MPID_nem_queue_ptr_t proc_recv_queue, 
227                      MPID_nem_queue_ptr_t proc_free_queue, 
228                      MPID_nem_cell_ptr_t proc_elements, int num_proc_elements,
229                      MPID_nem_cell_ptr_t module_elements, int num_module_elements, 
230                      MPID_nem_queue_ptr_t *module_free_queue, int ckpt_restart,
231                      MPIDI_PG_t *pg_p, int pg_rank,
232                      char **bc_val_p, int *val_max_sz_p)
233{   
234   int mpi_errno = MPI_SUCCESS ;
235   int index;
236
237   fprintf(stdout,"Size of MPID_nem_mad_module_vc_area_internal_t : %i | size of nm_sr_request_t :%i | Size of req_area : %i\n",
238         sizeof(MPID_nem_newmad_vc_area_internal_t),sizeof(nm_sr_request_t), sizeof(MPID_nem_newmad_req_area));
239   //MPIU_Assert( sizeof(MPID_nem_newmad_vc_area_internal_t) <= MPID_NEM_VC_NETMOD_AREA_LEN);
240   MPIU_Assert( sizeof(MPID_nem_newmad_req_area) <= MPID_NEM_REQ_NETMOD_AREA_LEN);
241
242   mpid_nem_newmad_myrank = pg_rank;
243   for (index = 0; index <  MPID_NEM_NMAD_MAX_NETS ; index++)
244   {
245       drv_id[index] = -1;
246       url[index]    = NULL;
247   }
248
249   init_mad(pg_p);
250
251   mpi_errno = MPID_nem_newmad_get_business_card(pg_rank,bc_val_p, val_max_sz_p);
252   if (mpi_errno) MPIU_ERR_POP (mpi_errno);
253
254   mpi_errno = MPIDI_CH3I_Register_anysource_notification(MPID_nem_newmad_anysource_posted, MPID_nem_newmad_anysource_matched);
255   if (mpi_errno) MPIU_ERR_POP(mpi_errno);
256
257   mpi_errno = MPID_nem_register_initcomp_cb(MPID_nem_newmad_post_init);
258   if (mpi_errno) MPIU_ERR_POP(mpi_errno);
259   
260   
261   fn_exit:
262       return mpi_errno;
263   fn_fail: 
264       goto fn_exit;
265}
266
267#undef FUNCNAME
268#define FUNCNAME MPID_nem_newmad_get_business_card
269#undef FCNAME
270#define FCNAME MPIDI_QUOTE(FUNCNAME)
271int
272MPID_nem_newmad_get_business_card (int my_rank, char **bc_val_p, int *val_max_sz_p)
273{
274   int mpi_errno = MPI_SUCCESS;
275   char name[MPID_NEM_NMAD_MAX_SIZE];
276   int index;
277   
278   gethostname(name,MPID_NEM_NMAD_MAX_SIZE);
279
280   mpi_errno = MPIU_Str_add_binary_arg (bc_val_p, val_max_sz_p, MPIDI_CH3I_HOSTNAME_KEY, name, strlen(name));
281   if (mpi_errno != MPIU_STR_SUCCESS){
282       if (mpi_errno == MPIU_STR_NOMEM){
283           MPIU_ERR_SET(mpi_errno, MPI_ERR_OTHER, "**buscard_len");
284       }
285       else{
286           MPIU_ERR_SET(mpi_errno, MPI_ERR_OTHER, "**buscard");
287       }
288       goto fn_exit;
289   }
290   
291   for(index = 0 ; index < mpid_nem_newmad_num_rails ; index ++){
292       mpi_errno = MPIU_Str_add_binary_arg (bc_val_p, val_max_sz_p, url_keys[index], url[index], strlen(url[index]));
293       if (mpi_errno != MPIU_STR_SUCCESS){
294           if (mpi_errno == MPIU_STR_NOMEM){
295               MPIU_ERR_SET(mpi_errno, MPI_ERR_OTHER, "**buscard_len");
296           }
297           else{
298               MPIU_ERR_SET(mpi_errno, MPI_ERR_OTHER, "**buscard");
299           }
300           goto fn_exit;
301       }
302   }
303
304   fn_exit:
305       return mpi_errno;
306   fn_fail: ATTRIBUTE((unused))
307       goto fn_exit;
308}
309
310#undef FUNCNAME
311#define FUNCNAME MPID_nem_newmad_get_from_bc
312#undef FCNAME
313#define FCNAME MPIDI_QUOTE(FUNCNAME)
314int
315MPID_nem_newmad_get_from_bc (const char *business_card, char *hostname, char *url, int index)
316{
317   int mpi_errno = MPI_SUCCESS;
318   int len;
319   
320   mpi_errno = MPIU_Str_get_binary_arg (business_card, MPIDI_CH3I_HOSTNAME_KEY, hostname, 
321                                        MPID_NEM_NMAD_MAX_SIZE, &len);
322   if ((mpi_errno != MPIU_STR_SUCCESS)){
323       MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER, "**argstr_hostd");
324   }
325
326   mpi_errno = MPIU_Str_get_binary_arg (business_card, url_keys[index], url, 
327                                        MPID_NEM_NMAD_MAX_SIZE, &len);
328   if ((mpi_errno != MPIU_STR_SUCCESS)){
329       MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER, "**argstr_hostd");
330   }
331   
332   fn_exit:
333     return mpi_errno;
334   fn_fail: 
335     goto fn_exit;
336}
337
338#undef FUNCNAME
339#define FUNCNAME MPID_nem_newmad_connect_to_root
340#undef FCNAME
341#define FCNAME MPIDI_QUOTE(FUNCNAME)
342int
343MPID_nem_newmad_connect_to_root (const char *business_card, MPIDI_VC_t *new_vc)
344{
345    int mpi_errno = MPI_SUCCESS;   
346 fn_exit:
347    return mpi_errno;
348 fn_fail: ATTRIBUTE((unused))
349    goto fn_exit;
350}
351
352#undef FUNCNAME
353#define FUNCNAME MPID_nem_newmad_send_init_msg
354#undef FCNAME
355#define FCNAME MPIDI_QUOTE(FUNCNAME)
356void
357MPID_nem_newmad_send_init_msg(nm_sr_event_t event, const nm_sr_event_info_t*info)
358{
359   --num_send_req;
360   return;
361}
362
363#undef FUNCNAME
364#define FUNCNAME MPID_nem_newmad_recv_init_msg
365#undef FCNAME
366#define FCNAME MPIDI_QUOTE(FUNCNAME)
367void
368MPID_nem_newmad_recv_init_msg(nm_sr_event_t event, const nm_sr_event_info_t*info)
369{
370   nm_sr_request_t            *p_request = info->recv_completed.p_request;
371   MPID_nem_newmad_init_req_t *init_req;
372   MPIDI_PG_t                 *pg_p;
373   int                         index;
374   
375   nm_sr_get_ref(mpid_nem_newmad_pcore, p_request, (void *)&init_req);
376   MPIU_Assert(init_req != NULL);
377   
378   /* get pg for comm world */
379   pg_p = MPIDI_Process.my_pg;
380   for (index = 0; index < pg_p->size ; index++)
381   {
382      if((index != mpid_nem_newmad_myrank) && !(MPID_NEM_IS_LOCAL(index))) 
383      {
384         MPIDI_VC_t *vc;
385         MPIDI_PG_Get_vc_set_active(pg_p, index, &vc);
386         if (vc->lpid == init_req->process_no)
387         {
388            VC_FIELD(vc, p_gate) = init_req->p_gate;
389            nm_gate_ref_set(VC_FIELD(vc, p_gate),(void*)vc);
390            break;
391         }
392      }
393   }
394   --num_recv_req;
395   return;
396}
397
398#undef FUNCNAME
399#define FUNCNAME MPID_nem_newmad_vc_init
400#undef FCNAME
401#define FCNAME MPIDI_QUOTE(FUNCNAME)
402int
403MPID_nem_newmad_vc_init (MPIDI_VC_t *vc)
404{
405    MPIDI_CH3I_VC           *vc_ch = (MPIDI_CH3I_VC *)vc->channel_private;
406    char                     business_card[MPID_NEM_NMAD_MAX_SIZE];
407    int                      mpi_errno = MPI_SUCCESS;   
408    int                      ret;
409    int                      index;
410
411    mpi_errno = vc->pg->getConnInfo(vc->pg_rank, business_card,MPID_NEM_NMAD_MAX_SIZE, vc->pg);
412    if (mpi_errno) MPIU_ERR_POP(mpi_errno);
413       
414    (((MPID_nem_newmad_vc_area *)((MPIDI_CH3I_VC *)(vc)->channel_private)->netmod_area.padding)->area) =
415        (MPID_nem_newmad_vc_area_internal_t *)MPIU_Malloc(sizeof(MPID_nem_newmad_vc_area_internal_t));
416
417    MPIU_Assert( (((MPID_nem_newmad_vc_area *)((MPIDI_CH3I_VC *)(vc)->channel_private)->netmod_area.padding)->area) != NULL);
418
419   ret = nm_core_gate_init(mpid_nem_newmad_pcore, &(init_reqs[vc->lpid].p_gate));
420   if (ret != NM_ESUCCESS) fprintf(stdout,"nm_core_gate_init returned ret = %d\n", ret);
421   
422    for(index = 0 ; index < mpid_nem_newmad_num_rails ; index ++)
423    {   
424        mpi_errno = MPID_nem_newmad_get_from_bc (business_card, VC_FIELD(vc, hostname), VC_FIELD(vc, url[index]), index);
425        if (mpi_errno) MPIU_ERR_POP (mpi_errno);
426       
427        VC_FIELD(vc, drv_id[index]) = drv_id[index];
428       
429        if (vc->lpid > mpid_nem_newmad_myrank){
430            ret = nm_core_gate_accept(mpid_nem_newmad_pcore,VC_FIELD(vc, p_gate), drv_id[index], NULL);
431        }
432        else if (vc->lpid < mpid_nem_newmad_myrank){
433            ret = nm_core_gate_connect(mpid_nem_newmad_pcore,VC_FIELD(vc, p_gate), drv_id[index], VC_FIELD(vc, url[index]));
434        }
435    }
436
437   vc->eager_max_msg_sz = 32768;
438   vc->rndvSend_fn      = NULL;
439   vc->sendNoncontig_fn = MPID_nem_newmad_SendNoncontig;
440   vc->comm_ops         = &comm_ops;
441
442   vc_ch->iStartContigMsg = MPID_nem_newmad_iStartContigMsg;
443   vc_ch->iSendContig     = MPID_nem_newmad_iSendContig;
444   
445 fn_exit:
446   return mpi_errno;
447 fn_fail:
448   goto fn_exit;
449}
450
451#undef FUNCNAME
452#define FUNCNAME MPID_nem_newmad_post_init
453#undef FCNAME
454#define FCNAME MPIDI_QUOTE(FUNCNAME)
455int MPID_nem_newmad_post_init(void)
456{
457   MPIDI_PG_t *pg_p;
458   int         index;
459
460   pg_p = MPIDI_Process.my_pg;
461   for (index = 0; index < pg_p->size ; index++)
462   {
463      if((index != mpid_nem_newmad_myrank) && !(MPID_NEM_IS_LOCAL(index))) 
464      {
465         MPIDI_VC_t *vc;
466         MPIDI_PG_Get_vc_set_active(pg_p, index, &vc);
467
468         if (vc->lpid > mpid_nem_newmad_myrank)
469         {
470            nm_sr_irecv_with_ref(mpid_nem_newmad_pcore,init_reqs[vc->lpid].p_gate,0xfffffffc,
471                                 &(init_reqs[vc->lpid].process_no),sizeof(int),&(init_reqs[vc->lpid].init_request),
472                                 (void *)&(init_reqs[vc->lpid]));
473             
474            nm_sr_request_monitor(mpid_nem_newmad_pcore,&(init_reqs[vc->lpid].init_request),NM_SR_EVENT_RECV_COMPLETED,
475                                  &MPID_nem_newmad_recv_init_msg);
476         }
477         else if (vc->lpid < mpid_nem_newmad_myrank)
478         {
479            nm_gate_ref_set(init_reqs[vc->lpid].p_gate,(void*)vc);
480            VC_FIELD(vc, p_gate) = init_reqs[vc->lpid].p_gate;
481           
482            nm_sr_isend(mpid_nem_newmad_pcore,init_reqs[vc->lpid].p_gate,0xfffffffc,&mpid_nem_newmad_myrank,sizeof(int),
483                        &(init_reqs[vc->lpid].init_request));
484           
485            nm_sr_request_monitor(mpid_nem_newmad_pcore,&(init_reqs[vc->lpid].init_request),NM_SR_EVENT_SEND_COMPLETED,
486                                  &MPID_nem_newmad_send_init_msg);
487         }
488      }
489   }
490   
491   while((num_recv_req > 0) || (num_send_req > 0))
492     nm_schedule(mpid_nem_newmad_pcore);
493   MPIU_Free(init_reqs);
494   
495   nm_sr_monitor(mpid_nem_newmad_pcore, NM_SR_EVENT_RECV_UNEXPECTED,&MPID_nem_newmad_get_adi_msg);
496   nm_sr_monitor(mpid_nem_newmad_pcore, NM_SR_EVENT_RECV_COMPLETED, &MPID_nem_newmad_get_rreq);
497   nm_sr_monitor(mpid_nem_newmad_pcore, NM_SR_EVENT_SEND_COMPLETED, &MPID_nem_newmad_handle_sreq);
498   
499   return 0;
500}
501
502#undef FUNCNAME
503#define FUNCNAME MPID_nem_newmad_vc_destroy
504#undef FCNAME
505#define FCNAME MPIDI_QUOTE(FUNCNAME)
506int MPID_nem_newmad_vc_destroy(MPIDI_VC_t *vc)
507{
508    int mpi_errno = MPI_SUCCESS;   
509
510    MPIU_Free((((MPID_nem_newmad_vc_area *)((MPIDI_CH3I_VC *)(vc)->channel_private)->netmod_area.padding)->area));
511
512 fn_exit:   
513       return mpi_errno;
514 fn_fail: ATTRIBUTE((unused))
515       goto fn_exit;
516}
517
518#undef FUNCNAME
519#define FUNCNAME MPID_nem_newmad_vc_terminate
520#undef FCNAME
521#define FCNAME MPIDI_QUOTE(FUNCNAME)
522int MPID_nem_newmad_vc_terminate (MPIDI_VC_t *vc)
523{
524    return MPI_SUCCESS;
525}
Note: See TracBrowser for help on using the browser.