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

📄 mpid_vc.c

📁 fortran并行计算包
💻 C
📖 第 1 页 / 共 2 页
字号:
    gpid[0] = pgid;    gpid[1] = vc->pg_rank;        return 0;}/*  * The following is a very simple code for looping through  * the GPIDs.  Note that this code requires that all processes * have information on the process groups. */#undef FUNCNAME#define FUNCNAME MPID_GPID_ToLpidArray#undef FCNAME#define FCNAME MPIDI_QUOTE(FUNCNAME)int MPID_GPID_ToLpidArray( int size, int gpid[], int lpid[] ){    int i, mpi_errno = MPI_SUCCESS;    int pgid;    MPIDI_PG_t *pg = 0;    for (i=0; i<size; i++) {	MPIDI_PG_Iterate_reset();	do {	    MPIDI_PG_Get_next( &pg );	    if (!pg) {		/* Internal error.  This gpid is unknown on this process */		printf("No matching pg foung for id = %d\n", pgid );		lpid[i] = -1;		MPIU_ERR_SET2(mpi_errno,MPI_ERR_INTERN, "**unknowngpid",			      "**unknowngpid %d %d", gpid[0], gpid[1] );		return mpi_errno;	    }	    MPIDI_PG_IdToNum( pg, &pgid );	    if (pgid == gpid[0]) {		/* found the process group.  gpid[1] is the rank in 		   this process group */		/* Sanity check on size */		if (pg->size > gpid[1]) {		    lpid[i] = pg->vct[gpid[1]].lpid;		}		else {		    lpid[i] = -1;		    MPIU_ERR_SET2(mpi_errno,MPI_ERR_INTERN, "**unknowngpid",				  "**unknowngpid %d %d", gpid[0], gpid[1] );		    return mpi_errno;		}		/* printf( "lpid[%d] = %d for gpid = (%d)%d\n", i, lpid[i], 		   gpid[0], gpid[1] ); */		break;	    }	} while (1);	gpid += 2;    }    return mpi_errno;}/*@  MPID_VCR_CommFromLpids - Create a new communicator from a given set  of lpids.    Notes:  This is used to create a communicator that is not a subset of some  existing communicator, for example, in a 'MPI_Comm_spawn' or   'MPI_Comm_connect/MPI_Comm_accept'. @*/#undef FUNCNAME#define FUNCNAME MPID_VCR_CommFromLpids#undef FCNAME#define FCNAME MPIDI_QUOTE(FUNCNAME)int MPID_VCR_CommFromLpids( MPID_Comm *newcomm_ptr, 			    int size, const int lpids[] ){    MPID_Comm *commworld_ptr;    int i;    commworld_ptr = MPIR_Process.comm_world;    /* Setup the communicator's vc table: remote group */    MPID_VCRT_Create( size, &newcomm_ptr->vcrt );    MPID_VCRT_Get_ptr( newcomm_ptr->vcrt, &newcomm_ptr->vcr );    for (i=0; i<size; i++) {	MPIDI_VC_t *vc = 0;	/* For rank i in the new communicator, find the corresponding	   virtual connection.  For lpids less than the size of comm_world,	   we can just take the corresponding entry from comm_world.	   Otherwise, we need to search through the process groups.	*/	/* printf( "[%d] Remote rank %d has lpid %d\n", 	   MPIR_Process.comm_world->rank, i, lpids[i] ); */	if (lpids[i] < commworld_ptr->remote_size) {	    vc = commworld_ptr->vcr[lpids[i]];	}	else {	    /* We must find the corresponding vcr for a given lpid */		    /* For now, this means iterating through the process groups */	    MPIDI_PG_t *pg = 0;	    int j;	    MPIDI_PG_Iterate_reset();	    /* Skip comm_world */	    MPIDI_PG_Get_next( &pg );	    do {		MPIDI_PG_Get_next( &pg );		if (!pg) {		    return MPIR_Err_create_code( MPI_SUCCESS, 				     MPIR_ERR_RECOVERABLE,				     "MPID_VCR_CommFromLpids", __LINE__,				     MPI_ERR_INTERN, "**intern", 0 );		}		/* FIXME: a quick check on the min/max values of the lpid		   for this process group could help speed this search */		for (j=0; j<pg->size; j++) {		    /*printf( "Checking lpid %d against %d in pg %s\n",			    lpids[i], pg->vct[j].lpid, (char *)pg->id );			    fflush(stdout); */		    if (pg->vct[j].lpid == lpids[i]) {			vc = &pg->vct[j];			/*printf( "found vc %x for lpid = %d in another pg\n", 			  (int)vc, lpids[i] );*/			break;		    }		}	    } while (!vc);	}	/* printf( "about to dup vc %x for lpid = %d in another pg\n", 	   (int)vc, lpids[i] ); */	/* Note that his will increment the ref count for the associate	   PG if necessary.  */	MPID_VCR_Dup( vc, &newcomm_ptr->vcr[i] );    }    return 0;}/* The following is a temporary hook to ensure that all processes in    a communicator have a set of process groups.    All arguments are input (all processes in comm must have gpids)   First: all processes check to see if they have information on all   of the process groups mentioned by id in the array of gpids.   The local result is LANDed with Allreduce.   If any process is missing process group information, then the   root process broadcasts the process group information as a string;    each process then uses this information to update to local process group   information (in the KVS cache that contains information about    contacting any process in the process groups).*/#undef FUNCNAME#define FUNCNAME MPID_PG_ForwardPGInfo#undef FCNAME#define FCNAME MPIDI_QUOTE(FUNCNAME)int MPID_PG_ForwardPGInfo( MPID_Comm *peer_ptr, MPID_Comm *comm_ptr, 			   int nPGids, const int gpids[], 			   int root ){    int i, allfound = 1, pgid, pgidWorld;    MPIDI_PG_t *pg = 0;    /* Get the pgid for CommWorld (always attached to the first process        group) */    MPIDI_PG_Iterate_reset();    MPIDI_PG_Get_next( &pg );    MPIDI_PG_IdToNum( pg, &pgidWorld );        /* Extract the unique process groups */    for (i=0; i<nPGids && allfound; i++) {	if (gpids[0] != pgidWorld) {	    /* Add this gpid to the list of values to check */	    /* FIXME: For testing, we just test in place */	    MPIDI_PG_Iterate_reset();	    do {		MPIDI_PG_Get_next( &pg );		if (!pg) {		    /* We don't know this pgid */		    allfound = 0;		    break;		}		MPIDI_PG_IdToNum( pg, &pgid );	    } while (pgid != gpids[0]);	}	gpids += 2;    }    /* See if everyone is happy */    NMPI_Allreduce( MPI_IN_PLACE, &allfound, 1, MPI_INT, MPI_LAND, 		    comm_ptr->handle );    if (allfound) return MPI_SUCCESS;    /* FIXME: We need a cleaner way to handle this case than using an ifdef.       We could have an empty version of MPID_PG_BCast in ch3u_port.c, but       that's a rather crude way of addressing this problem.  Better is to       make the handling of local and remote PIDS for the dynamic process       case part of the dynamic process "module"; devices that don't support       dynamic processes (and hence have only COMM_WORLD) could optimize for        that case */#ifndef MPIDI_CH3_HAS_NO_DYNAMIC_PROCESS    /* We need to share the process groups.  We use routines       from ch3u_port.c */    MPID_PG_BCast( peer_ptr, comm_ptr, root );#endif    return MPI_SUCCESS;}#undef FUNCNAME#define FUNCNAME MPIDI_CH3U_VC_FinishPending#undef FCNAME#define FCNAME MPIDI_QUOTE(FUNCNAME)static int MPIDI_CH3U_VC_FinishPending( MPIDI_VCRT_t *vcrt ){    int mpi_errno = MPI_SUCCESS;    MPIDI_VC_t **vc;    int i, size, nPending;    MPID_Progress_state progress_state;     MPIDI_STATE_DECL(MPID_STATE_MPIDI_CH3U_VC_FINISHPENDING);    MPIDI_FUNC_ENTER(MPID_STATE_MPIDI_CH3U_VC_FINISHPENDING);    do {	/* Compute the number of pending ops.	   A virtual connection has pending operations if the state	   is not INACTIVE or if the sendq is not null */	nPending = 0;	vc       = vcrt->vcr_table;	size     = vcrt->size;	/* printf( "Size = %d\n", size ); fflush(stdout); */	for (i=0; i<size; i++) {	    if (vc[i]->state != MPIDI_VC_STATE_INACTIVE) {		/* FIXME: Printf for debugging */		printf ("state for vc[%d] is %d\n",			i, vc[i]->state ); fflush(stdout);		nPending++;	    }#if 0	    /* FIXME: We shouldn't have any references to the channel-specific	       fields in this part of the code.  This case should actually	       not be needed; if there is a pending send element, the	       top-level state should not be inactive */	    if (vc[i]->ch.sendq_head) {		/* FIXME: Printf for debugging */		printf( "Nonempty sendQ for vc[%d]\n", i ); fflush(stdout);		nPending++;	    }#endif	}	if (nPending > 0) {	    printf( "Panic! %d pending operations!\n", nPending );	    fflush(stdout);	    MPIU_Assert( nPending == 0 );	}	else {	    break;	}	MPID_Progress_start(&progress_state);	MPIU_DBG_MSG_D(CH3_DISCONNECT,VERBOSE,		       "Waiting for %d close operations",		       nPending);	mpi_errno = MPID_Progress_wait(&progress_state);	/* --BEGIN ERROR HANDLING-- */	if (mpi_errno != MPI_SUCCESS) {	    MPID_Progress_end(&progress_state);	    MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER,				"**ch3|close_progress");	}	/* --END ERROR HANDLING-- */	MPID_Progress_end(&progress_state);    } while(nPending > 0); fn_exit:    MPIDI_FUNC_EXIT(MPID_STATE_MPIDI_CH3U_VC_FINISHPENDING);    return mpi_errno; fn_fail:    goto fn_exit;}/* * MPIDI_CH3U_Comm_FinishPending - Complete any pending operations on the  * communicator.   * * Notes:  * This should be used before freeing or disconnecting a communicator. * * For better scalability, we might want to form a list of VC's with  * pending operations. */#undef FUNCNAME#define FUNCNAME MPIDI_CH3U_Comm_FinishPending#undef FCNAME#define FCNAME MPIDI_QUOTE(FUNCNAME)int MPIDI_CH3U_Comm_FinishPending( MPID_Comm *comm_ptr ){    int mpi_errno = MPI_SUCCESS;    MPIDI_STATE_DECL(MPID_STATE_MPIDI_CH3U_COMM_FINISHPENDING);    MPIDI_FUNC_ENTER(MPID_STATE_MPIDI_CH3U_COMM_FINISHPENDING);    mpi_errno = MPIDI_CH3U_VC_FinishPending( comm_ptr->vcrt );    if (!mpi_errno && comm_ptr->local_vcrt) {	mpi_errno = MPIDI_CH3U_VC_FinishPending( comm_ptr->local_vcrt );    }    MPIDI_FUNC_EXIT(MPID_STATE_MPIDI_CH3U_COMM_FINISHPENDING);    return mpi_errno;}/* ----------------------------------------------------------------------- *//* Routines to initialize a VC *//* * The lpid counter counts new processes that this process knows about. */static int lpid_counter = 0;/* Fully initialize a VC.  This invokes the channel-specific    VC initialization routine MPIDI_CH3_VC_Init . */int MPIDI_VC_Init( MPIDI_VC_t *vc, MPIDI_PG_t *pg, int rank ){    vc->state = MPIDI_VC_STATE_INACTIVE;    MPIU_Object_set_ref(vc, 0);    vc->handle  = MPID_VCONN;    vc->pg      = pg;    vc->pg_rank = rank;    vc->lpid    = lpid_counter++;    MPIDI_VC_Init_seqnum_send(vc);    MPIDI_VC_Init_seqnum_recv(vc);    vc->rndvSend_fn           = MPIDI_CH3_RndvSend;    vc->rndvRecv_fn           = MPIDI_CH3_RecvRndv;    vc->eager_max_msg_sz      = MPIDI_CH3_EAGER_MAX_MSG_SIZE;    vc->sendNoncontig_fn      = MPIDI_CH3_SendNoncontig;    MPIU_CALL(MPIDI_CH3,VC_Init( vc ));    MPIU_DBG_PrintVCState(vc);    return MPI_SUCCESS;}

⌨️ 快捷键说明

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