⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mpid_init.c

📁 fortran并行计算包
💻 C
📖 第 1 页 / 共 2 页
字号:
  fn_exit:    MPIDI_FUNC_EXIT(MPID_STATE_MPID_INIT);    return mpi_errno;    /* --BEGIN ERROR HANDLING-- */  fn_fail:    goto fn_exit;    /* --END ERROR HANDLING-- */}/* This allows each channel to perform final initialization after the rest of MPI_Init completes.  */int MPID_InitCompleted( void ){    int mpi_errno;    mpi_errno = MPIU_CALL(MPIDI_CH3,InitCompleted());    return mpi_errno;}/* * Initialize the process group structure by using PMI calls. * This routine initializes PMI and uses PMI calls to setup the  * process group structures. *  */static int InitPG( int *argc, char ***argv, 		   int *has_args, int *has_env, int *has_parent, 		   int *pg_rank_p, MPIDI_PG_t **pg_p ){    int pmi_errno;    int mpi_errno = MPI_SUCCESS;    int pg_rank, pg_size, appnum, pg_id_sz;    int usePMI=1;    char *pg_id;    MPIDI_PG_t *pg = 0;    /* See if the channel will provide the PMI values.  The channel     is responsible for defining HAVE_CH3_PRE_INIT and providing     the MPIDI_CH3_Pre_init function.  */    /* FIXME: Document this */#ifdef HAVE_CH3_PRE_INIT    {	int setvals;	mpi_errno = MPIDI_CH3_Pre_init( &setvals, has_parent, &pg_rank, 					&pg_size );	if (mpi_errno) {	    goto fn_fail;	}	if (setvals) usePMI = 0;    }#endif     /* If we use PMI here, make the PMI calls to get the       basic values.  Note that systems that return setvals == true       do not make use of PMI for the KVS routines either (it is       assumed that the discover connection information through some       other mechanism */    /* FIXME: We may want to allow the channel to ifdef out the use       of PMI calls, or ask the channel to provide stubs that        return errors if the routines are in fact used */    if (usePMI) {	/*	 * Initialize the process manangement interface (PMI), 	 * and get rank and size information about our process group	 */	pmi_errno = PMI_Init(has_parent);	if (pmi_errno != PMI_SUCCESS) {	    MPIU_ERR_SETANDJUMP1(mpi_errno,MPI_ERR_OTHER, "**pmi_init",			     "**pmi_init %d", pmi_errno);	}	pmi_errno = PMI_Get_rank(&pg_rank);	if (pmi_errno != PMI_SUCCESS) {	    MPIU_ERR_SETANDJUMP1(mpi_errno,MPI_ERR_OTHER, "**pmi_get_rank",			     "**pmi_get_rank %d", pmi_errno);	}	pmi_errno = PMI_Get_size(&pg_size);	if (pmi_errno != 0) {	MPIU_ERR_SETANDJUMP1(mpi_errno,MPI_ERR_OTHER, "**pmi_get_size",			     "**pmi_get_size %d", pmi_errno);	}		pmi_errno = PMI_Get_appnum(&appnum);	if (pmi_errno != PMI_SUCCESS) {	    MPIU_ERR_SETANDJUMP1(mpi_errno,MPI_ERR_OTHER, "**pmi_get_appnum",				 "**pmi_get_appnum %d", pmi_errno);	}	/* Note that if pmi is not availble, the value of MPI_APPNUM is 	   not set */	if (appnum != -1) {	    MPIR_Process.attrs.appnum = appnum;	}		/* Now, initialize the process group information with PMI calls */	/*	 * Get the process group id	 */	pmi_errno = PMI_Get_id_length_max(&pg_id_sz);	if (pmi_errno != PMI_SUCCESS) {	    MPIU_ERR_SETANDJUMP1(mpi_errno,MPI_ERR_OTHER,				 "**pmi_get_id_length_max", 				 "**pmi_get_id_length_max %d", pmi_errno);	}	/* This memory will be freed by the PG_Destroy if there is an error */	pg_id = MPIU_Malloc(pg_id_sz + 1);	if (pg_id == NULL) {	    MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER, "**nomem");	}	/* Note in the singleton init case, the pg_id is a dummy.	   We'll want to replace this value if we join an 	   Process manager */	pmi_errno = PMI_Get_id(pg_id, pg_id_sz);	if (pmi_errno != PMI_SUCCESS) {	    MPIU_ERR_SETANDJUMP1(mpi_errno,MPI_ERR_OTHER, "**pmi_get_id",				 "**pmi_get_id %d", pmi_errno);	}    }    else {	/* Create a default pg id */	pg_id = MPIU_Malloc(2);	if (pg_id == NULL) {	    MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER, "**nomem");	}	MPIU_Strncpy( pg_id, "0", 2 );    }    /*     * Initialize the process group tracking subsystem     */    mpi_errno = MPIDI_PG_Init(argc, argv, 			     MPIDI_CH3I_PG_Compare_ids, MPIDI_CH3I_PG_Destroy);    if (mpi_errno != MPI_SUCCESS) {	MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER,"**dev|pg_init");    }    /*     * Create a new structure to track the process group for our MPI_COMM_WORLD     */    mpi_errno = MPIDI_PG_Create(pg_size, pg_id, &pg);    if (mpi_errno != MPI_SUCCESS) {	MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER, "**dev|pg_create");    }    /* FIXME: We can allow the channels to tell the PG how to get       connection information by passing the pg to the channel init routine */    if (usePMI) {	/* Tell the process group how to get connection information */	MPIDI_PG_InitConnKVS( pg );#if 0	/* If we're supporting the debugger, we can save our host and 	   pid here.  This publishes the data in the kvs space. 	   This allows the MPI processes to access the information 	   about the other processes without any PMI changes. */#ifdef HAVE_DEBUGGER_SUPPORT	{	    char key[64];	    char myinfo[512];	    MPIU_Snprintf( key, sizeof(key), "hpid-%d", pg_rank );	    MPIU_Snpritnf( myinfo, sizeof(key), "%s:%d", hostname, getpid() );	    PMI_KVS_Put( pg->world->connData, key, myinfo );	}#endif#endif    }    /* FIXME: Who is this for and where does it belong? */#ifdef USE_MPIU_DBG_PRINT_VC    MPIU_DBG_parent_str = (*has_parent) ? "+" : "";#endif    /* FIXME: has_args and has_env need to come from PMI eventually... */    *has_args = TRUE;    *has_env  = TRUE;    *pg_p      = pg;    *pg_rank_p = pg_rank;     fn_exit:    return mpi_errno; fn_fail:    /* --BEGIN ERROR HANDLING-- */    if (pg) {	MPIDI_PG_Destroy( pg );    }    goto fn_exit;    /* --END ERROR HANDLING-- */}/* * Create the storage for the business card.  * * The routine MPIDI_CH3I_BCFree should be called with the original  * value *bc_val_p .  Note that the routines that set the value  * of the businesscard return a pointer to the first free location, * so you need to remember the original location in order to free  * it later. * */int MPIDI_CH3I_BCInit( char **bc_val_p, int *val_max_sz_p ){    int pmi_errno;    int mpi_errno = MPI_SUCCESS;    pmi_errno = PMI_KVS_Get_value_length_max(val_max_sz_p);    if (pmi_errno != PMI_SUCCESS)    {	MPIU_ERR_SETANDJUMP1(mpi_errno,MPI_ERR_OTHER, 			     "**pmi_kvs_get_value_length_max",			     "**pmi_kvs_get_value_length_max %d", pmi_errno);    }    /* This memroy is returned by this routine */    *bc_val_p = MPIU_Malloc(*val_max_sz_p);    if (*bc_val_p == NULL) {	MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER, "**nomem");    }        /* Add a null to simplify looking at the bc */    **bc_val_p = 0;  fn_exit:    return mpi_errno;  fn_fail:    goto fn_exit;}/* Free the business card.  This routine should be called once the business   card is published. */int MPIDI_CH3I_BCFree( char *bc_val ){    /* */    if (bc_val) {	MPIU_Free( bc_val );    }        return 0;}/* FIXME: The PG code should supply these, since it knows how the    pg_ids and other data are represented */static int MPIDI_CH3I_PG_Compare_ids(void * id1, void * id2){    return (strcmp((char *) id1, (char *) id2) == 0) ? TRUE : FALSE;}static int MPIDI_CH3I_PG_Destroy(MPIDI_PG_t * pg){    if (pg->id != NULL)    { 	MPIU_Free(pg->id);    }        return MPI_SUCCESS;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -