📄 comm_cid.c
字号:
/* * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana * University Research and Technology * Corporation. All rights reserved. * Copyright (c) 2004-2006 The University of Tennessee and The University * of Tennessee Research Foundation. All rights * reserved. * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow * * $HEADER$ */#include "ompi_config.h"#include "orte/dss/dss.h"#include "opal/util/convert.h"#include "orte/mca/ns/ns_types.h"#include "ompi/communicator/communicator.h"#include "ompi/proc/proc.h"#include "ompi/constants.h"#include "ompi/class/ompi_pointer_array.h"#include "opal/class/opal_list.h"#include "ompi/mca/pml/pml.h"#include "ompi/mca/coll/base/base.h"#include "orte/mca/rml/rml.h"#include "ompi/request/request.h"#if defined(c_plusplus) || defined(__cplusplus)extern "C" {#endif/** * These functions make sure, that we determine the global result over * an intra communicators (simple), an inter-communicator and a * pseudo inter-communicator described by two separate intra-comms * and a bridge-comm (intercomm-create scenario). */typedef int ompi_comm_cid_allredfct (int *inbuf, int* outbuf, int count, struct ompi_op_t *op, ompi_communicator_t *comm, ompi_communicator_t *bridgecomm, void* lleader, void* rleader, int send_first );static int ompi_comm_allreduce_intra (int *inbuf, int* outbuf, int count, struct ompi_op_t *op, ompi_communicator_t *intercomm, ompi_communicator_t *bridgecomm, void* local_leader, void* remote_ledaer, int send_first );static int ompi_comm_allreduce_inter (int *inbuf, int *outbuf, int count, struct ompi_op_t *op, ompi_communicator_t *intercomm, ompi_communicator_t *bridgecomm, void* local_leader, void* remote_leader, int send_first );static int ompi_comm_allreduce_intra_bridge(int *inbuf, int* outbuf, int count, struct ompi_op_t *op, ompi_communicator_t *intercomm, ompi_communicator_t *bridgecomm, void* local_leader, void* remote_leader, int send_first);static int ompi_comm_allreduce_intra_oob (int *inbuf, int* outbuf, int count, struct ompi_op_t *op, ompi_communicator_t *intercomm, ompi_communicator_t *bridgecomm, void* local_leader, void* remote_leader, int send_first );static int ompi_comm_register_cid (uint32_t contextid);static int ompi_comm_unregister_cid (uint32_t contextid);static uint32_t ompi_comm_lowest_cid ( void );struct ompi_comm_reg_t{ opal_list_item_t super; uint32_t cid;};typedef struct ompi_comm_reg_t ompi_comm_reg_t;OMPI_DECLSPEC OBJ_CLASS_DECLARATION(ompi_comm_reg_t);static void ompi_comm_reg_constructor(ompi_comm_reg_t *regcom);static void ompi_comm_reg_destructor(ompi_comm_reg_t *regcom);OBJ_CLASS_INSTANCE (ompi_comm_reg_t, opal_list_item_t, ompi_comm_reg_constructor, ompi_comm_reg_destructor );#if OMPI_HAVE_THREAD_SUPPORTstatic opal_mutex_t ompi_cid_lock;#endif /* OMPI_HAVE_THREAD_SUPPORT */static opal_list_t ompi_registered_comms;int ompi_comm_nextcid ( ompi_communicator_t* newcomm, ompi_communicator_t* comm, ompi_communicator_t* bridgecomm, void* local_leader, void* remote_leader, int mode, int send_first ){ int nextlocal_cid; int nextcid; int done=0; int response=0, glresponse=0; bool flag; int start=ompi_mpi_communicators.lowest_free; int i; ompi_comm_cid_allredfct* allredfnct; /** * Determine which implementation of allreduce we have to use * for the current scenario */ switch (mode) { case OMPI_COMM_CID_INTRA: allredfnct=(ompi_comm_cid_allredfct*)ompi_comm_allreduce_intra; break; case OMPI_COMM_CID_INTER: allredfnct=(ompi_comm_cid_allredfct*)ompi_comm_allreduce_inter; break; case OMPI_COMM_CID_INTRA_BRIDGE: allredfnct=(ompi_comm_cid_allredfct*)ompi_comm_allreduce_intra_bridge; break; case OMPI_COMM_CID_INTRA_OOB: allredfnct=(ompi_comm_cid_allredfct*)ompi_comm_allreduce_intra_oob; break; default: return MPI_UNDEFINED; break; } OPAL_THREAD_LOCK(&ompi_cid_lock); ompi_comm_register_cid (comm->c_contextid); OPAL_THREAD_UNLOCK(&ompi_cid_lock); while (!done) { /** * This is the real algorithm described in the doc */ OPAL_THREAD_LOCK(&ompi_cid_lock); if (comm->c_contextid != ompi_comm_lowest_cid() ) { /* if not lowest cid, we do not continue, but sleep and try again */ OPAL_THREAD_UNLOCK(&ompi_cid_lock); continue; } OPAL_THREAD_UNLOCK(&ompi_cid_lock); for (i=start; i < mca_pml.pml_max_contextid ; i++) { flag=ompi_pointer_array_test_and_set_item(&ompi_mpi_communicators, i, comm); if (true == flag) { nextlocal_cid = i; break; } } (allredfnct)(&nextlocal_cid, &nextcid, 1, MPI_MAX, comm, bridgecomm, local_leader, remote_leader, send_first ); if (nextcid == nextlocal_cid) { response = 1; /* fine with me */ } else { ompi_pointer_array_set_item(&ompi_mpi_communicators, nextlocal_cid, NULL); flag = ompi_pointer_array_test_and_set_item(&ompi_mpi_communicators, nextcid, comm ); if (true == flag) { response = 1; /* works as well */ } else { response = 0; /* nope, not acceptable */ } } (allredfnct)(&response, &glresponse, 1, MPI_MIN, comm, bridgecomm, local_leader, remote_leader, send_first ); if (1 == glresponse) { done = 1; /* we are done */ break; } else if ( 0 == glresponse ) { if ( 1 == response ) { /* we could use that, but other don't agree */ ompi_pointer_array_set_item(&ompi_mpi_communicators, nextcid, NULL); } start = nextcid+1; /* that's where we can start the next round */ } } /* set the according values to the newcomm */ newcomm->c_contextid = nextcid; newcomm->c_f_to_c_index = newcomm->c_contextid; ompi_pointer_array_set_item (&ompi_mpi_communicators, nextcid, newcomm); OPAL_THREAD_LOCK(&ompi_cid_lock); ompi_comm_unregister_cid (comm->c_contextid); OPAL_THREAD_UNLOCK(&ompi_cid_lock); return (MPI_SUCCESS);}/**************************************************************************//**************************************************************************//**************************************************************************/static void ompi_comm_reg_constructor (ompi_comm_reg_t *regcom){ regcom->cid=MPI_UNDEFINED;}static void ompi_comm_reg_destructor (ompi_comm_reg_t *regcom){}void ompi_comm_reg_init (void){ OBJ_CONSTRUCT(&ompi_registered_comms, opal_list_t);}void ompi_comm_reg_finalize (void){ OBJ_DESTRUCT(&ompi_registered_comms);}static int ompi_comm_register_cid (uint32_t cid ){ opal_list_item_t *item=NULL; ompi_comm_reg_t *regcom=NULL; ompi_comm_reg_t *newentry = OBJ_NEW(ompi_comm_reg_t); newentry->cid = cid; if ( !(opal_list_is_empty (&ompi_registered_comms)) ) { for (item = opal_list_get_first(&ompi_registered_comms); item != opal_list_get_end(&ompi_registered_comms); item = opal_list_get_next(item)) { regcom = (ompi_comm_reg_t *)item; if ( regcom->cid > cid ) { break; } } opal_list_insert_pos (&ompi_registered_comms, (opal_list_item_t *)regcom, (opal_list_item_t *)newentry); } else { opal_list_append (&ompi_registered_comms, (opal_list_item_t *)newentry); } return OMPI_SUCCESS;}static int ompi_comm_unregister_cid (uint32_t cid){ ompi_comm_reg_t *regcom=NULL; opal_list_item_t *item=opal_list_remove_first(&ompi_registered_comms); regcom = (ompi_comm_reg_t *) item; OBJ_RELEASE(regcom); return OMPI_SUCCESS;}static uint32_t ompi_comm_lowest_cid (void){ ompi_comm_reg_t *regcom=NULL; opal_list_item_t *item=opal_list_get_first (&ompi_registered_comms); regcom = (ompi_comm_reg_t *)item; return regcom->cid;}/**************************************************************************//**************************************************************************//**************************************************************************//* This routine serves two purposes: * - the allreduce acts as a kind of Barrier, * which avoids, that we have incoming fragments * on the new communicator before everybody has set * up the comm structure. * - some components (e.g. the collective MagPIe component * might want to generate new communicators and communicate * using the new comm. Thus, it can just be called after * the 'barrier'. * * The reason that this routine is in comm_cid and not in * comm.c is, that this file contains the allreduce implementations * which are required, and thus we avoid having duplicate code... */int ompi_comm_activate ( ompi_communicator_t* newcomm, ompi_communicator_t* comm, ompi_communicator_t* bridgecomm, void* local_leader, void* remote_leader, int mode, int send_first, mca_base_component_t *collcomponent ){ int ok=0, gok=0; ompi_comm_cid_allredfct* allredfnct; /* Step 1: the barrier, after which it is allowed to * send messages over the new communicator */ switch (mode) { case OMPI_COMM_CID_INTRA: allredfnct=(ompi_comm_cid_allredfct*)ompi_comm_allreduce_intra; break; case OMPI_COMM_CID_INTER: allredfnct=(ompi_comm_cid_allredfct*)ompi_comm_allreduce_inter; break; case OMPI_COMM_CID_INTRA_BRIDGE: allredfnct=(ompi_comm_cid_allredfct*)ompi_comm_allreduce_intra_bridge; break; case OMPI_COMM_CID_INTRA_OOB: allredfnct=(ompi_comm_cid_allredfct*)ompi_comm_allreduce_intra_oob; break; default: return MPI_UNDEFINED; break; } (allredfnct)(&ok, &gok, 1, MPI_MIN, comm, bridgecomm, local_leader, remote_leader, send_first ); /* Check to see if this process is in the new communicator. Specifically, this function is invoked by all proceses in the old communicator, regardless of whether they are in the new communicator or not. This is because it is far simpler to use MPI collective functions on the old communicator to determine some data for the new communicator (e.g., remote_leader) than to kludge up our own pseudo-collective routines over just the processes in the new communicator. Hence, *all* processes in the old communicator need to invoke this function. That being said, only processes in the new communicator need to select a coll module for the new communicator. More specifically, proceses who are not in the new communicator should *not* select a coll module -- for example, ompi_comm_rank(newcomm) returns MPI_UNDEFINED for processes who are not in the new communicator. This can cause errors in the selection / initialization of a coll module. Plus, it's wasteful -- processes in the new communicator will end up
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -