1
1
openmpi/ompi/communicator/comm.c

1644 строки
56 KiB
C
Исходник Обычный вид История

/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2013 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 (c) 2007-2011 University of Houston. All rights reserved.
Per RFC, bring in the following changes: * Remove paffinity, maffinity, and carto frameworks -- they've been wholly replaced by hwloc. * Move ompi_mpi_init() affinity-setting/checking code down to ORTE. * Update sm, smcuda, wv, and openib components to no longer use carto. Instead, use hwloc data. There are still optimizations possible in the sm/smcuda BTLs (i.e., making multiple mpools). Also, the old carto-based code found out how many NUMA nodes were ''available'' -- not how many were used ''in this job''. The new hwloc-using code computes the same value -- it was not updated to calculate how many NUMA nodes are used ''by this job.'' * Note that I cannot compile the smcuda and wv BTLs -- I ''think'' they're right, but they need to be verified by their owners. * The openib component now does a bunch of stuff to figure out where "near" OpenFabrics devices are. '''THIS IS A CHANGE IN DEFAULT BEHAVIOR!!''' and still needs to be verified by OpenFabrics vendors (I do not have a NUMA machine with an OpenFabrics device that is a non-uniform distance from multiple different NUMA nodes). * Completely rewrite the OMPI_Affinity_str() routine from the "affinity" mpiext extension. This extension now understands hyperthreads; the output format of it has changed a bit to reflect this new information. * Bunches of minor changes around the code base to update names/types from maffinity/paffinity-based names to hwloc-based names. * Add some helper functions into the hwloc base, mainly having to do with the fact that we have the hwloc data reporting ''all'' topology information, but sometimes you really only want the (online | available) data. This commit was SVN r26391.
2012-05-07 18:52:54 +04:00
* Copyright (c) 2007-2012 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved.
* Copyright (c) 2011-2013 INRIA. All rights reserved.
* Copyright (c) 2011-2013 Universite Bordeaux 1
* Copyright (c) 2012 Oak Ridge National Labs. All rights reserved.
* Copyright (c) 2012-2013 Los Alamos National Security, LLC.
* All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "ompi_config.h"
#include <string.h>
#include <stdio.h>
#include "ompi/constants.h"
Per RFC, bring in the following changes: * Remove paffinity, maffinity, and carto frameworks -- they've been wholly replaced by hwloc. * Move ompi_mpi_init() affinity-setting/checking code down to ORTE. * Update sm, smcuda, wv, and openib components to no longer use carto. Instead, use hwloc data. There are still optimizations possible in the sm/smcuda BTLs (i.e., making multiple mpools). Also, the old carto-based code found out how many NUMA nodes were ''available'' -- not how many were used ''in this job''. The new hwloc-using code computes the same value -- it was not updated to calculate how many NUMA nodes are used ''by this job.'' * Note that I cannot compile the smcuda and wv BTLs -- I ''think'' they're right, but they need to be verified by their owners. * The openib component now does a bunch of stuff to figure out where "near" OpenFabrics devices are. '''THIS IS A CHANGE IN DEFAULT BEHAVIOR!!''' and still needs to be verified by OpenFabrics vendors (I do not have a NUMA machine with an OpenFabrics device that is a non-uniform distance from multiple different NUMA nodes). * Completely rewrite the OMPI_Affinity_str() routine from the "affinity" mpiext extension. This extension now understands hyperthreads; the output format of it has changed a bit to reflect this new information. * Bunches of minor changes around the code base to update names/types from maffinity/paffinity-based names to hwloc-based names. * Add some helper functions into the hwloc base, mainly having to do with the fact that we have the hwloc data reporting ''all'' topology information, but sometimes you really only want the (online | available) data. This commit was SVN r26391.
2012-05-07 18:52:54 +04:00
#include "opal/mca/hwloc/base/base.h"
#include "opal/dss/dss.h"
#include "ompi/proc/proc.h"
#include "opal/threads/mutex.h"
#include "opal/util/bit_ops.h"
#include "opal/util/output.h"
#include "ompi/mca/topo/topo.h"
#include "ompi/mca/topo/base/base.h"
#include "ompi/mca/dpm/dpm.h"
#include "ompi/attribute/attribute.h"
#include "ompi/communicator/communicator.h"
#include "ompi/mca/pml/pml.h"
#include "ompi/request/request.h"
/*
** sort-function for MPI_Comm_split
*/
static int rankkeycompare(const void *, const void *);
/**
* to fill the rest of the stuff for the communicator
*/
static int ompi_comm_fill_rest (ompi_communicator_t *comm,
int num_procs,
ompi_proc_t **proc_pointers,
int my_rank,
ompi_errhandler_t *errh );
/*
** typedef for the allgather_intra required in comm_split.
** the reason for introducing this abstraction is, that
** for Comm_split for inter-coms, we do not have this
** functions, so we need to emulate it.
*/
typedef int ompi_comm_allgatherfct (void* inbuf, int incount, MPI_Datatype intype,
void* outbuf, int outcount, MPI_Datatype outtype,
ompi_communicator_t *comm,
mca_coll_base_module_t *data);
static int ompi_comm_allgather_emulate_intra (void* inbuf, int incount, MPI_Datatype intype,
void* outbuf, int outcount,
MPI_Datatype outtype,
ompi_communicator_t *comm,
mca_coll_base_module_t *data);
static int ompi_comm_copy_topo (ompi_communicator_t *oldcomm,
ompi_communicator_t *newcomm);
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/
/*
* This is the function setting all elements of a communicator.
* All other routines are just used to determine these elements.
*/
int ompi_comm_set ( ompi_communicator_t **ncomm,
ompi_communicator_t *oldcomm,
int local_size,
int *local_ranks,
int remote_size,
int *remote_ranks,
opal_hash_table_t *attr,
ompi_errhandler_t *errh,
bool copy_topocomponent,
ompi_group_t *local_group,
ompi_group_t *remote_group )
{
ompi_communicator_t *newcomm = NULL;
int ret;
/* ompi_comm_allocate */
newcomm = OBJ_NEW(ompi_communicator_t);
/* fill in the inscribing hyper-cube dimensions */
newcomm->c_cube_dim = opal_cube_dim(local_size);
newcomm->c_id_available = MPI_UNDEFINED;
newcomm->c_id_start_index = MPI_UNDEFINED;
if (NULL == local_group) {
/* determine how the list of local_rank can be stored most
efficiently */
ret = ompi_group_incl(oldcomm->c_local_group, local_size,
local_ranks, &newcomm->c_local_group);
} else {
newcomm->c_local_group = local_group;
OBJ_RETAIN(newcomm->c_local_group);
ompi_group_increment_proc_count(newcomm->c_local_group);
}
newcomm->c_my_rank = newcomm->c_local_group->grp_my_rank;
/* Set remote group and duplicate the local comm, if applicable */
if ( 0 < remote_size) {
if ( NULL == remote_group ) {
ret = ompi_group_incl(oldcomm->c_remote_group, remote_size,
remote_ranks, &newcomm->c_remote_group);
} else {
newcomm->c_remote_group = remote_group;
OBJ_RETAIN(newcomm->c_remote_group);
ompi_group_increment_proc_count(newcomm->c_remote_group);
}
newcomm->c_flags |= OMPI_COMM_INTER;
if ( OMPI_COMM_IS_INTRA(oldcomm) ) {
ompi_comm_dup(oldcomm, &newcomm->c_local_comm);
} else {
ompi_comm_dup(oldcomm->c_local_comm, &newcomm->c_local_comm);
}
} else {
newcomm->c_remote_group = newcomm->c_local_group;
OBJ_RETAIN(newcomm->c_remote_group);
}
/* Check how many different jobids are represented in this communicator.
Necessary for the disconnect of dynamic communicators. */
if ( 0 < local_size ) {
ompi_dpm.mark_dyncomm (newcomm);
}
/* Set error handler */
newcomm->error_handler = errh;
OBJ_RETAIN ( newcomm->error_handler );
/* Set Topology, if required and if available */
if ( copy_topocomponent && (NULL != oldcomm->c_topo) ) {
/**
* The MPI standard is pretty clear on this, the topology information
* behave as info keys, and is copied only on MPI_Comm_dup.
*/
if (OMPI_SUCCESS != (ret = ompi_comm_copy_topo(oldcomm, newcomm))) {
ompi_comm_free(&newcomm);
return ret;
}
}
/* Copy attributes and call according copy functions, if required */
if (NULL != oldcomm->c_keyhash) {
if (NULL != attr) {
ompi_attr_hash_init(&newcomm->c_keyhash);
if (OMPI_SUCCESS != (ret = ompi_attr_copy_all (COMM_ATTR, oldcomm,
newcomm, attr,
newcomm->c_keyhash))) {
ompi_comm_free(&newcomm);
return ret;
}
}
}
*ncomm = newcomm;
return (OMPI_SUCCESS);
}
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/
/*
** Counterpart to MPI_Comm_group. To be used within OMPI functions.
*/
int ompi_comm_group ( ompi_communicator_t* comm, ompi_group_t **group )
{
/* increment reference counters for the group */
OBJ_RETAIN(comm->c_local_group);
/* increase also the reference counter for the procs */
ompi_group_increment_proc_count(comm->c_local_group);
*group = comm->c_local_group;
return OMPI_SUCCESS;
}
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/
/*
** Counterpart to MPI_Comm_create. To be used within OMPI.
*/
int ompi_comm_create ( ompi_communicator_t *comm, ompi_group_t *group,
ompi_communicator_t **newcomm )
{
ompi_communicator_t *newcomp = NULL;
int rsize , lsize;
int mode,i,j;
int *allranks=NULL;
int *rranks=NULL;
int rc = OMPI_SUCCESS;
lsize = group->grp_proc_count;
if ( OMPI_COMM_IS_INTER(comm) ) {
int tsize;
tsize = ompi_comm_remote_size(comm);
allranks = (int *) malloc ( tsize * sizeof(int));
if ( NULL == allranks ) {
rc = OMPI_ERR_OUT_OF_RESOURCE;
goto exit;
}
rc = comm->c_coll.coll_allgather ( &(group->grp_my_rank),
1, MPI_INT, allranks,
1, MPI_INT, comm,
comm->c_coll.coll_allgather_module);
if ( OMPI_SUCCESS != rc ) {
goto exit;
}
/* Count number of procs in future remote group */
for (rsize=0, i = 0; i < tsize; i++) {
if ( MPI_UNDEFINED != allranks[i] ) {
rsize++;
}
}
/* If any of those groups is empty, we have to return
MPI_COMM_NULL */
if ( 0 == rsize || 0 == group->grp_proc_count ) {
newcomp = MPI_COMM_NULL;
rc = OMPI_SUCCESS;
goto exit;
}
/* Set proc-pointers for remote group */
rranks = (int *) malloc ( rsize * sizeof(int));
if ( NULL == rranks ) {
rc = OMPI_ERR_OUT_OF_RESOURCE;
goto exit;
}
for ( j = 0, i = 0; i < tsize; i++ ) {
if ( MPI_UNDEFINED != allranks[i] ) {
rranks[j] = i;
j++;
}
}
mode = OMPI_COMM_CID_INTER;
} else {
rsize = 0;
rranks = NULL;
mode = OMPI_COMM_CID_INTRA;
}
rc = ompi_comm_set ( &newcomp, /* new comm */
comm, /* old comm */
lsize, /* local_size */
NULL, /* local_ranks */
rsize, /* remote_size */
rranks, /* remote_ranks */
NULL, /* attrs */
comm->error_handler, /* error handler */
false, /* dont copy the topo */
group, /* local group */
NULL /* remote group */
);
if ( OMPI_SUCCESS != rc ) {
goto exit;
}
if ( NULL == newcomm ) {
rc = MPI_ERR_INTERN;
goto exit;
}
/* Determine context id. It is identical to f_2_c_handle */
rc = ompi_comm_nextcid ( newcomp, /* new communicator */
comm, /* old comm */
NULL, /* bridge comm */
NULL, /* local leader */
NULL, /* remote_leader */
mode, /* mode */
-1 ); /* send first */
if ( OMPI_SUCCESS != rc ) {
goto exit;
}
/* Set name for debugging purposes */
snprintf(newcomp->c_name, MPI_MAX_OBJECT_NAME, "MPI COMMUNICATOR %d CREATE FROM %d",
newcomp->c_contextid, comm->c_contextid );
/* Activate the communicator and init coll-component */
so here is what happens: in the v1.2 series the cid's could never go above the max. allowed for a particular pml. Because of that, pml_add_comm never checked for the cid, and in fact pml_add_comm was called in comm_set, which is *before* we knew the cid. in the v1.3 series (and trunk) we check now the cid to detect overflow, and because of that pml_add_comm has been moved *after* the cid allocation routine, namely into the comm_activate routine. in the v1.2 series, the comm_activate contained a synchronization step of the old communicator in order to prevent incoming fragments on the new communicator, with the main problem being that the allreduce in the communicator allocation finished at different times on different processes, and thus, this scenario could and did really occur. in the v1.3 series, the comm_activate does not contain the synchronization step anymore, since we introduced the new queue for fragments with unknown cid. The problem is however, that whether a fragment is known or not is decided by using ompi_comm_lookup(), which will return something useful as soon as the cid allocation finished, even before pml_add_comm has been called. So there is a small time gap where we will not post a message into queue for unknown cid's, but we can also not look up the process structure belonging to the rank in that comm ( that is in pml_ob1_match_recv_frag or something like that). The current fix reintroduces the synchronization step in comm_activate, and ensures that no fragment can be received for a new communicator before the synchronization occurs , and thus comm_nextcid() and pml_add_comm has been called. It seems to be the safest and easiest way for now. Welcome back, v1.2. This commit was SVN r21970.
2009-09-17 18:37:02 +04:00
rc = ompi_comm_activate( &newcomp, /* new communicator */
comm,
NULL,
NULL,
NULL,
mode,
-1 );
if ( OMPI_SUCCESS != rc ) {
goto exit;
}
/* Check whether we are part of the new comm.
If not, we have to free the structure again.
However, we could not avoid the comm_nextcid step, since
all processes of the original comm have to participate in
that function call. Additionally, all errhandler stuff etc.
has to be set to make ompi_comm_free happy */
if ( MPI_UNDEFINED == newcomp->c_local_group->grp_my_rank ) {
ompi_comm_free ( &newcomp );
}
exit:
if ( NULL != allranks ) {
free ( allranks );
}
if ( NULL != rranks ) {
free ( rranks );
}
*newcomm = newcomp;
return ( rc );
}
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/
/*
** Counterpart to MPI_Comm_split. To be used within OMPI (e.g. MPI_Cart_sub).
*/
int ompi_comm_split( ompi_communicator_t* comm, int color, int key,
ompi_communicator_t **newcomm, bool pass_on_topo )
{
int myinfo[2];
int size, my_size;
int my_rsize;
int mode;
int rsize;
int i, loc;
int inter;
int *results=NULL, *sorted=NULL;
int *rresults=NULL, *rsorted=NULL;
int rc=OMPI_SUCCESS;
ompi_communicator_t *newcomp = NULL;
int *lranks=NULL, *rranks=NULL;
ompi_comm_allgatherfct *allgatherfct=NULL;
/* Step 1: determine all the information for the local group */
/* --------------------------------------------------------- */
/* sort according to color and rank. Gather information from everyone */
myinfo[0] = color;
myinfo[1] = key;
size = ompi_comm_size ( comm );
inter = OMPI_COMM_IS_INTER(comm);
if ( inter ) {
allgatherfct = (ompi_comm_allgatherfct *)ompi_comm_allgather_emulate_intra;
} else {
allgatherfct = (ompi_comm_allgatherfct *)comm->c_coll.coll_allgather;
}
results = (int*) malloc ( 2 * size * sizeof(int));
if ( NULL == results ) {
return OMPI_ERR_OUT_OF_RESOURCE;
}
rc = allgatherfct( myinfo, 2, MPI_INT, results, 2, MPI_INT, comm, comm->c_coll.coll_allgather_module );
if ( OMPI_SUCCESS != rc ) {
goto exit;
}
/* how many have the same color like me */
for ( my_size = 0, i=0; i < size; i++) {
if ( results[(2*i)+0] == color) {
my_size++;
}
}
sorted = (int *) malloc ( sizeof( int ) * my_size * 2);
if ( NULL == sorted) {
rc = OMPI_ERR_OUT_OF_RESOURCE;
goto exit;
}
/* ok we can now fill this info */
for( loc = 0, i = 0; i < size; i++ ) {
if ( results[(2*i)+0] == color) {
sorted[(2*loc)+0] = i; /* copy org rank */
sorted[(2*loc)+1] = results[(2*i)+1]; /* copy key */
loc++;
}
}
/* the new array needs to be sorted so that it is in 'key' order */
/* if two keys are equal then it is sorted in original rank order! */
if(my_size>1){
qsort ((int*)sorted, my_size, sizeof(int)*2, rankkeycompare);
}
/* put group elements in a list */
lranks = (int *) malloc ( my_size * sizeof(int));
if ( NULL == lranks ) {
rc = OMPI_ERR_OUT_OF_RESOURCE;
goto exit;
}
for (i = 0; i < my_size; i++) {
lranks[i] = sorted[i*2];
}
/* Step 2: determine all the information for the remote group */
/* --------------------------------------------------------- */
if ( inter ) {
rsize = comm->c_remote_group->grp_proc_count;
rresults = (int *) malloc ( rsize * 2 * sizeof(int));
if ( NULL == rresults ) {
rc = OMPI_ERR_OUT_OF_RESOURCE;
goto exit;
}
/* this is an allgather on an inter-communicator */
rc = comm->c_coll.coll_allgather( myinfo, 2, MPI_INT, rresults, 2,
MPI_INT, comm,
comm->c_coll.coll_allgather_module);
if ( OMPI_SUCCESS != rc ) {
goto exit;
}
/* how many have the same color like me */
for ( my_rsize = 0, i=0; i < rsize; i++) {
if ( rresults[(2*i)+0] == color) {
my_rsize++;
}
}
rsorted = (int *) malloc ( sizeof( int ) * my_rsize * 2);
if ( NULL == rsorted) {
rc = OMPI_ERR_OUT_OF_RESOURCE;
goto exit;
}
/* ok we can now fill this info */
for( loc = 0, i = 0; i < rsize; i++ ) {
if ( rresults[(2*i)+0] == color) {
rsorted[(2*loc)+0] = i; /* org rank */
rsorted[(2*loc)+1] = rresults[(2*i)+1]; /* key */
loc++;
}
}
/* the new array needs to be sorted so that it is in 'key' order */
/* if two keys are equal then it is sorted in original rank order! */
if(my_rsize>1) {
qsort ((int*)rsorted, my_rsize, sizeof(int)*2, rankkeycompare);
}
/* put group elements in a list */
rranks = (int *) malloc ( my_rsize * sizeof(int));
if ( NULL == rranks) {
rc = OMPI_ERR_OUT_OF_RESOURCE;
goto exit;
}
for (i = 0; i < my_rsize; i++) {
rranks[i] = rsorted[i*2];
}
mode = OMPI_COMM_CID_INTER;
} else {
my_rsize = 0;
rranks = NULL;
mode = OMPI_COMM_CID_INTRA;
}
/* Step 3: set up the communicator */
/* --------------------------------------------------------- */
/* Create the communicator finally */
rc = ompi_comm_set ( &newcomp, /* new comm */
comm, /* old comm */
my_size, /* local_size */
lranks, /* local_ranks */
my_rsize, /* remote_size */
rranks, /* remote_ranks */
NULL, /* attrs */
comm->error_handler,/* error handler */
pass_on_topo,
NULL, /* local group */
NULL /* remote group */
);
if ( NULL == newcomp ) {
rc = MPI_ERR_INTERN;
goto exit;
}
if ( OMPI_SUCCESS != rc ) {
goto exit;
}
/* Determine context id. It is identical to f_2_c_handle */
rc = ompi_comm_nextcid ( newcomp, /* new communicator */
comm, /* old comm */
NULL, /* bridge comm */
NULL, /* local leader */
NULL, /* remote_leader */
mode, /* mode */
-1 ); /* send first, doesn't matter */
if ( OMPI_SUCCESS != rc ) {
goto exit;
}
/* Set name for debugging purposes */
snprintf(newcomp->c_name, MPI_MAX_OBJECT_NAME, "MPI COMMUNICATOR %d SPLIT FROM %d",
newcomp->c_contextid, comm->c_contextid );
This commit fixes a bug on how to deal with the potential if a 'dependent' communicator that we created has a lower CID than the parent comm. This can happen when using the hierarch collective communication module or for inter-communicators (since we make a duplicate of the original communicator). This is not a problem as long as the user calls MPI_Comm_free on the parent communicator. However, if the communicators are not freed by the user but released by Open MPI in MPI_Finalize, we walk through the list of still available communicators and free them one by one. Thus, local_comm is freed before the actual inter-communicator. However, the local_comm pointer in the inter communicator will still contain the 'previous' address of the local_comm and thus this will lead to a segmentation violation. In order to prevent that from happening, we increase the reference counter local_comm by one if its CID is lower than the parent. We cannot increase however its reference counter if the CID of local_comm is larger than the CID of the inter communicators, since a regular MPI_Comm_free would leave in that the case the local_comm hanging around and thus we would not recycle CID's properly, which was the reason and the cause for this trouble. This commit fixes tickets 2094 and 2166. Note however, that I want to close them manually, since a slightly different patch is required for the 1.4 series. This commit will have to be applied for the 1.5 series. And I will need a volunteer to review it. This commit was SVN r22671.
2010-02-20 02:45:30 +03:00
/* set the rank to MPI_UNDEFINED. This prevents in comm_activate
* the collective module selection for a communicator that will
* be freed anyway.
*/
if ( MPI_UNDEFINED == color ) {
newcomp->c_local_group->grp_my_rank = MPI_UNDEFINED;
This commit fixes a bug on how to deal with the potential if a 'dependent' communicator that we created has a lower CID than the parent comm. This can happen when using the hierarch collective communication module or for inter-communicators (since we make a duplicate of the original communicator). This is not a problem as long as the user calls MPI_Comm_free on the parent communicator. However, if the communicators are not freed by the user but released by Open MPI in MPI_Finalize, we walk through the list of still available communicators and free them one by one. Thus, local_comm is freed before the actual inter-communicator. However, the local_comm pointer in the inter communicator will still contain the 'previous' address of the local_comm and thus this will lead to a segmentation violation. In order to prevent that from happening, we increase the reference counter local_comm by one if its CID is lower than the parent. We cannot increase however its reference counter if the CID of local_comm is larger than the CID of the inter communicators, since a regular MPI_Comm_free would leave in that the case the local_comm hanging around and thus we would not recycle CID's properly, which was the reason and the cause for this trouble. This commit fixes tickets 2094 and 2166. Note however, that I want to close them manually, since a slightly different patch is required for the 1.4 series. This commit will have to be applied for the 1.5 series. And I will need a volunteer to review it. This commit was SVN r22671.
2010-02-20 02:45:30 +03:00
}
/* Activate the communicator and init coll-component */
so here is what happens: in the v1.2 series the cid's could never go above the max. allowed for a particular pml. Because of that, pml_add_comm never checked for the cid, and in fact pml_add_comm was called in comm_set, which is *before* we knew the cid. in the v1.3 series (and trunk) we check now the cid to detect overflow, and because of that pml_add_comm has been moved *after* the cid allocation routine, namely into the comm_activate routine. in the v1.2 series, the comm_activate contained a synchronization step of the old communicator in order to prevent incoming fragments on the new communicator, with the main problem being that the allreduce in the communicator allocation finished at different times on different processes, and thus, this scenario could and did really occur. in the v1.3 series, the comm_activate does not contain the synchronization step anymore, since we introduced the new queue for fragments with unknown cid. The problem is however, that whether a fragment is known or not is decided by using ompi_comm_lookup(), which will return something useful as soon as the cid allocation finished, even before pml_add_comm has been called. So there is a small time gap where we will not post a message into queue for unknown cid's, but we can also not look up the process structure belonging to the rank in that comm ( that is in pml_ob1_match_recv_frag or something like that). The current fix reintroduces the synchronization step in comm_activate, and ensures that no fragment can be received for a new communicator before the synchronization occurs , and thus comm_nextcid() and pml_add_comm has been called. It seems to be the safest and easiest way for now. Welcome back, v1.2. This commit was SVN r21970.
2009-09-17 18:37:02 +04:00
rc = ompi_comm_activate( &newcomp, /* new communicator */
comm,
NULL,
NULL,
NULL,
mode,
-1 );
if ( OMPI_SUCCESS != rc ) {
goto exit;
}
exit:
if ( NULL != results ) {
free ( results );
}
if ( NULL != sorted ) {
free ( sorted );
}
if ( NULL != rresults) {
free ( rresults );
}
if ( NULL != rsorted ) {
free ( rsorted );
}
if ( NULL != lranks ) {
free ( lranks );
}
if ( NULL != rranks ) {
free ( rranks );
}
/* Step 4: if we are not part of the comm, free the struct */
/* --------------------------------------------------------- */
if ( NULL != newcomp && MPI_UNDEFINED == color ) {
ompi_comm_free ( &newcomp );
}
*newcomm = newcomp;
return ( rc );
}
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/
int
ompi_comm_split_type(ompi_communicator_t *comm,
int split_type, int key,
ompi_info_t *info,
ompi_communicator_t** newcomm)
{
int myinfo[2];
int size, my_size;
int my_rsize;
int mode;
int rsize;
int i, loc;
int inter;
int *results=NULL, *sorted=NULL;
int *rresults=NULL, *rsorted=NULL;
int rc=OMPI_SUCCESS;
ompi_communicator_t *newcomp = NULL;
int *lranks=NULL, *rranks=NULL;
ompi_comm_allgatherfct *allgatherfct=NULL;
/* Step 1: determine all the information for the local group */
/* --------------------------------------------------------- */
/* sort according to participation and rank. Gather information from everyone */
myinfo[0] = (split_type == MPI_COMM_TYPE_SHARED) ? 1 : 0;
myinfo[1] = key;
size = ompi_comm_size ( comm );
inter = OMPI_COMM_IS_INTER(comm);
if ( inter ) {
allgatherfct = (ompi_comm_allgatherfct *)ompi_comm_allgather_emulate_intra;
} else {
allgatherfct = (ompi_comm_allgatherfct *)comm->c_coll.coll_allgather;
}
results = (int*) malloc ( 2 * size * sizeof(int));
if ( NULL == results ) {
return OMPI_ERR_OUT_OF_RESOURCE;
}
rc = allgatherfct( myinfo, 2, MPI_INT, results, 2, MPI_INT, comm, comm->c_coll.coll_allgather_module );
if ( OMPI_SUCCESS != rc ) {
goto exit;
}
/* how many are participating and on my node? */
for ( my_size = 0, i=0; i < size; i++) {
if ( results[(2*i)+0] == 1) {
if (OPAL_PROC_ON_LOCAL_NODE(ompi_group_peer_lookup(comm->c_local_group, i)->proc_flags)) {
my_size++;
}
}
}
sorted = (int *) malloc ( sizeof( int ) * my_size * 2);
if ( NULL == sorted) {
rc = OMPI_ERR_OUT_OF_RESOURCE;
goto exit;
}
/* ok we can now fill this info */
for( loc = 0, i = 0; i < size; i++ ) {
if ( results[(2*i)+0] == 1) {
if (OPAL_PROC_ON_LOCAL_NODE(ompi_group_peer_lookup(comm->c_local_group, i)->proc_flags)) {
sorted[(2*loc)+0] = i; /* copy org rank */
sorted[(2*loc)+1] = results[(2*i)+1]; /* copy key */
loc++;
}
}
}
/* the new array needs to be sorted so that it is in 'key' order */
/* if two keys are equal then it is sorted in original rank order! */
if(my_size>1){
qsort ((int*)sorted, my_size, sizeof(int)*2, rankkeycompare);
}
/* put group elements in a list */
lranks = (int *) malloc ( my_size * sizeof(int));
if ( NULL == lranks ) {
rc = OMPI_ERR_OUT_OF_RESOURCE;
goto exit;
}
for (i = 0; i < my_size; i++) {
lranks[i] = sorted[i*2];
}
/* Step 2: determine all the information for the remote group */
/* --------------------------------------------------------- */
if ( inter ) {
rsize = comm->c_remote_group->grp_proc_count;
rresults = (int *) malloc ( rsize * 2 * sizeof(int));
if ( NULL == rresults ) {
rc = OMPI_ERR_OUT_OF_RESOURCE;
goto exit;
}
/* this is an allgather on an inter-communicator */
rc = comm->c_coll.coll_allgather( myinfo, 2, MPI_INT, rresults, 2,
MPI_INT, comm,
comm->c_coll.coll_allgather_module);
if ( OMPI_SUCCESS != rc ) {
goto exit;
}
/* how many are participating and on my node? */
for ( my_rsize = 0, i=0; i < rsize; i++) {
if ( rresults[(2*i)+0] == 1) {
if (OPAL_PROC_ON_LOCAL_NODE(ompi_group_peer_lookup(comm->c_remote_group, i)->proc_flags)) {
my_rsize++;
}
}
}
rsorted = (int *) malloc ( sizeof( int ) * my_rsize * 2);
if ( NULL == rsorted) {
rc = OMPI_ERR_OUT_OF_RESOURCE;
goto exit;
}
/* ok we can now fill this info */
for( loc = 0, i = 0; i < rsize; i++ ) {
if ( rresults[(2*i)+0] == 1) {
if (OPAL_PROC_ON_LOCAL_NODE(ompi_group_peer_lookup(comm->c_remote_group, i)->proc_flags)) {
rsorted[(2*loc)+0] = i; /* org rank */
rsorted[(2*loc)+1] = rresults[(2*i)+1]; /* key */
loc++;
}
}
}
/* the new array needs to be sorted so that it is in 'key' order */
/* if two keys are equal then it is sorted in original rank order! */
if(my_rsize>1) {
qsort ((int*)rsorted, my_rsize, sizeof(int)*2, rankkeycompare);
}
/* put group elements in a list */
rranks = (int *) malloc ( my_rsize * sizeof(int));
if ( NULL == rranks) {
rc = OMPI_ERR_OUT_OF_RESOURCE;
goto exit;
}
for (i = 0; i < my_rsize; i++) {
rranks[i] = rsorted[i*2];
}
mode = OMPI_COMM_CID_INTER;
} else {
my_rsize = 0;
rranks = NULL;
mode = OMPI_COMM_CID_INTRA;
}
/* Step 3: set up the communicator */
/* --------------------------------------------------------- */
/* Create the communicator finally */
rc = ompi_comm_set ( &newcomp, /* new comm */
comm, /* old comm */
my_size, /* local_size */
lranks, /* local_ranks */
my_rsize, /* remote_size */
rranks, /* remote_ranks */
NULL, /* attrs */
comm->error_handler,/* error handler */
false, /* don't copy the topo */
NULL, /* local group */
NULL ); /* remote group */
if ( NULL == newcomm ) {
rc = MPI_ERR_INTERN;
goto exit;
}
if ( OMPI_SUCCESS != rc ) {
goto exit;
}
/* Determine context id. It is identical to f_2_c_handle */
rc = ompi_comm_nextcid ( newcomp, /* new communicator */
comm, /* old comm */
NULL, /* bridge comm */
NULL, /* local leader */
NULL, /* remote_leader */
mode, /* mode */
-1 ); /* send first, doesn't matter */
if ( OMPI_SUCCESS != rc ) {
goto exit;
}
/* Set name for debugging purposes */
snprintf(newcomp->c_name, MPI_MAX_OBJECT_NAME, "MPI COMMUNICATOR %d SPLIT_TYPE FROM %d",
newcomp->c_contextid, comm->c_contextid );
/* set the rank to MPI_UNDEFINED. This prevents in comm_activate
* the collective module selection for a communicator that will
* be freed anyway.
*/
if ( MPI_UNDEFINED == split_type ) {
newcomp->c_local_group->grp_my_rank = MPI_UNDEFINED;
}
/* Activate the communicator and init coll-component */
rc = ompi_comm_activate( &newcomp, /* new communicator */
comm,
NULL,
NULL,
NULL,
mode,
-1 );
if ( OMPI_SUCCESS != rc ) {
goto exit;
}
exit:
if ( NULL != results ) {
free ( results );
}
if ( NULL != sorted ) {
free ( sorted );
}
if ( NULL != rresults) {
free ( rresults );
}
if ( NULL != rsorted ) {
free ( rsorted );
}
if ( NULL != lranks ) {
free ( lranks );
}
if ( NULL != rranks ) {
free ( rranks );
}
/* Step 4: if we are not part of the comm, free the struct */
/* --------------------------------------------------------- */
if ( NULL != newcomp && MPI_UNDEFINED == split_type ) {
ompi_comm_free ( &newcomp );
}
*newcomm = newcomp;
return ( rc );
}
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/
int ompi_comm_dup ( ompi_communicator_t * comm, ompi_communicator_t **newcomm )
{
ompi_communicator_t *newcomp = NULL;
int rsize = 0, mode = OMPI_COMM_CID_INTRA, rc = OMPI_SUCCESS;
if ( OMPI_COMM_IS_INTER ( comm ) ){
rsize = comm->c_remote_group->grp_proc_count;
mode = OMPI_COMM_CID_INTER;
}
*newcomm = MPI_COMM_NULL;
rc = ompi_comm_set ( &newcomp, /* new comm */
comm, /* old comm */
comm->c_local_group->grp_proc_count, /* local_size */
NULL, /* local_procs*/
rsize, /* remote_size */
NULL, /* remote_procs */
comm->c_keyhash, /* attrs */
comm->error_handler, /* error handler */
true, /* copy the topo */
comm->c_local_group, /* local group */
comm->c_remote_group ); /* remote group */
if ( NULL == newcomp ) {
rc = MPI_ERR_INTERN;
return rc;
}
if ( MPI_SUCCESS != rc) {
return rc;
}
/* Determine context id. It is identical to f_2_c_handle */
rc = ompi_comm_nextcid ( newcomp, /* new communicator */
comm, /* old comm */
NULL, /* bridge comm */
NULL, /* local leader */
NULL, /* remote_leader */
mode, /* mode */
-1 ); /* send_first */
if ( OMPI_SUCCESS != rc ) {
return rc;
}
/* Set name for debugging purposes */
snprintf(newcomp->c_name, MPI_MAX_OBJECT_NAME, "MPI COMMUNICATOR %d DUP FROM %d",
newcomp->c_contextid, comm->c_contextid );
/* activate communicator and init coll-module */
so here is what happens: in the v1.2 series the cid's could never go above the max. allowed for a particular pml. Because of that, pml_add_comm never checked for the cid, and in fact pml_add_comm was called in comm_set, which is *before* we knew the cid. in the v1.3 series (and trunk) we check now the cid to detect overflow, and because of that pml_add_comm has been moved *after* the cid allocation routine, namely into the comm_activate routine. in the v1.2 series, the comm_activate contained a synchronization step of the old communicator in order to prevent incoming fragments on the new communicator, with the main problem being that the allreduce in the communicator allocation finished at different times on different processes, and thus, this scenario could and did really occur. in the v1.3 series, the comm_activate does not contain the synchronization step anymore, since we introduced the new queue for fragments with unknown cid. The problem is however, that whether a fragment is known or not is decided by using ompi_comm_lookup(), which will return something useful as soon as the cid allocation finished, even before pml_add_comm has been called. So there is a small time gap where we will not post a message into queue for unknown cid's, but we can also not look up the process structure belonging to the rank in that comm ( that is in pml_ob1_match_recv_frag or something like that). The current fix reintroduces the synchronization step in comm_activate, and ensures that no fragment can be received for a new communicator before the synchronization occurs , and thus comm_nextcid() and pml_add_comm has been called. It seems to be the safest and easiest way for now. Welcome back, v1.2. This commit was SVN r21970.
2009-09-17 18:37:02 +04:00
rc = ompi_comm_activate( &newcomp, /* new communicator */
comm,
NULL,
NULL,
NULL,
mode,
-1 );
if ( OMPI_SUCCESS != rc ) {
return rc;
}
*newcomm = newcomp;
return MPI_SUCCESS;
}
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/
int ompi_comm_compare(ompi_communicator_t *comm1, ompi_communicator_t *comm2, int *result) {
/* local variables */
ompi_communicator_t *comp1, *comp2;
int size1, size2, rsize1, rsize2;
int lresult, rresult=MPI_CONGRUENT;
int cmp_result;
comp1 = (ompi_communicator_t *) comm1;
comp2 = (ompi_communicator_t *) comm2;
if ( comp1->c_contextid == comp2->c_contextid ) {
*result = MPI_IDENT;
return MPI_SUCCESS;
}
if ( MPI_COMM_NULL == comm1 || MPI_COMM_NULL == comm2 ) {
*result = MPI_UNEQUAL;
return MPI_SUCCESS;
}
/* compare sizes of local and remote groups */
size1 = ompi_comm_size (comp1);
size2 = ompi_comm_size (comp2);
rsize1 = ompi_comm_remote_size (comp1);
rsize2 = ompi_comm_remote_size (comp2);
if ( size1 != size2 || rsize1 != rsize2 ) {
*result = MPI_UNEQUAL;
return MPI_SUCCESS;
}
/* Compare local groups */
ompi_group_compare((ompi_group_t *)comp1->c_local_group,
(ompi_group_t *)comp2->c_local_group,
&cmp_result);
/* MPI_IDENT resulting from the group comparison is
* MPI_CONGRUENT for communicators.
* All others results are the same.
*/
if( MPI_IDENT == cmp_result ) {
lresult = MPI_CONGRUENT;
} else {
lresult = cmp_result;
}
if ( rsize1 > 0 ) {
/* Compare remote groups for inter-communicators */
ompi_group_compare((ompi_group_t *)comp1->c_remote_group,
(ompi_group_t *)comp2->c_remote_group,
&cmp_result);
/* MPI_IDENT resulting from the group comparison is
* MPI_CONGRUENT for communicators.
* All others results are the same.
*/
if( MPI_IDENT == cmp_result ) {
rresult = MPI_CONGRUENT;
} else {
rresult = cmp_result;
}
}
/* determine final results */
if ( MPI_CONGRUENT == rresult ) {
*result = lresult;
}
else if ( MPI_SIMILAR == rresult ) {
if ( MPI_SIMILAR == lresult || MPI_CONGRUENT == lresult ) {
*result = MPI_SIMILAR;
}
else {
*result = MPI_UNEQUAL;
}
}
else if ( MPI_UNEQUAL == rresult ) {
*result = MPI_UNEQUAL;
}
return OMPI_SUCCESS;
}
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/
int ompi_comm_set_name (ompi_communicator_t *comm, const char *name )
{
#ifdef USE_MUTEX_FOR_COMMS
OPAL_THREAD_LOCK(&(comm->c_lock));
#endif
memset(comm->c_name, 0, MPI_MAX_OBJECT_NAME);
strncpy(comm->c_name, name, MPI_MAX_OBJECT_NAME);
comm->c_name[MPI_MAX_OBJECT_NAME - 1] = 0;
comm->c_flags |= OMPI_COMM_NAMEISSET;
#ifdef USE_MUTEX_FOR_COMMS
OPAL_THREAD_UNLOCK(&(comm->c_lock));
#endif
return OMPI_SUCCESS;
}
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/
/*
* Implementation of MPI_Allgather for the local_group in an inter-comm.
* The algorithm consists of two steps:
* 1. an inter-gather to rank 0 in remote group
* 2. an inter-bcast from rank 0 in remote_group.
*/
static int ompi_comm_allgather_emulate_intra( void *inbuf, int incount,
MPI_Datatype intype, void* outbuf,
int outcount, MPI_Datatype outtype,
ompi_communicator_t *comm,
mca_coll_base_module_t *data)
{
int rank, size, rsize, i, rc;
int *tmpbuf=NULL;
MPI_Request *req=NULL, sendreq;
rsize = ompi_comm_remote_size(comm);
size = ompi_comm_size(comm);
rank = ompi_comm_rank(comm);
/* Step 1: the gather-step */
if ( 0 == rank ) {
tmpbuf = (int *) malloc (rsize*outcount*sizeof(int));
req = (MPI_Request *)malloc (rsize*outcount*sizeof(MPI_Request));
if ( NULL == tmpbuf || NULL == req ) {
return (OMPI_ERR_OUT_OF_RESOURCE);
}
for ( i=0; i<rsize; i++) {
rc = MCA_PML_CALL(irecv( &tmpbuf[outcount*i], outcount, outtype, i,
OMPI_COMM_ALLGATHER_TAG, comm, &req[i] ));
if ( OMPI_SUCCESS != rc ) {
goto exit;
}
}
}
rc = MCA_PML_CALL(isend( inbuf, incount, intype, 0, OMPI_COMM_ALLGATHER_TAG,
MCA_PML_BASE_SEND_STANDARD, comm, &sendreq ));
if ( OMPI_SUCCESS != rc ) {
goto exit;
}
if ( 0 == rank ) {
rc = ompi_request_wait_all (rsize, req, MPI_STATUSES_IGNORE);
if ( OMPI_SUCCESS != rc ) {
goto exit;
}
}
rc = ompi_request_wait_all (1, &sendreq, MPI_STATUS_IGNORE);
if ( OMPI_SUCCESS != rc ) {
goto exit;
}
/* Step 2: the inter-bcast step */
rc = MCA_PML_CALL(irecv (outbuf, size*outcount, outtype, 0,
OMPI_COMM_ALLGATHER_TAG, comm, &sendreq));
if ( OMPI_SUCCESS != rc ) {
goto exit;
}
if ( 0 == rank ) {
for ( i=0; i < rsize; i++ ){
rc = MCA_PML_CALL(send (tmpbuf, rsize*outcount, outtype, i,
OMPI_COMM_ALLGATHER_TAG,
MCA_PML_BASE_SEND_STANDARD, comm));
if ( OMPI_SUCCESS != rc ) {
goto exit;
}
}
}
rc = ompi_request_wait_all (1, &sendreq, MPI_STATUS_IGNORE );
exit:
if ( NULL != req ) {
free ( req );
}
if ( NULL != tmpbuf ) {
free ( tmpbuf );
}
return (rc);
}
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/
/*
** Counterpart to MPI_Comm_free. To be used within OMPI.
** The freeing of all attached objects (groups, errhandlers
** etc. ) has moved to the destructor.
*/
int ompi_comm_free( ompi_communicator_t **comm )
{
int ret;
This commit fixes a bug on how to deal with the potential if a 'dependent' communicator that we created has a lower CID than the parent comm. This can happen when using the hierarch collective communication module or for inter-communicators (since we make a duplicate of the original communicator). This is not a problem as long as the user calls MPI_Comm_free on the parent communicator. However, if the communicators are not freed by the user but released by Open MPI in MPI_Finalize, we walk through the list of still available communicators and free them one by one. Thus, local_comm is freed before the actual inter-communicator. However, the local_comm pointer in the inter communicator will still contain the 'previous' address of the local_comm and thus this will lead to a segmentation violation. In order to prevent that from happening, we increase the reference counter local_comm by one if its CID is lower than the parent. We cannot increase however its reference counter if the CID of local_comm is larger than the CID of the inter communicators, since a regular MPI_Comm_free would leave in that the case the local_comm hanging around and thus we would not recycle CID's properly, which was the reason and the cause for this trouble. This commit fixes tickets 2094 and 2166. Note however, that I want to close them manually, since a slightly different patch is required for the 1.4 series. This commit will have to be applied for the 1.5 series. And I will need a volunteer to review it. This commit was SVN r22671.
2010-02-20 02:45:30 +03:00
int cid = (*comm)->c_contextid;
int is_extra_retain = OMPI_COMM_IS_EXTRA_RETAIN(*comm);
This commit fixes a bug on how to deal with the potential if a 'dependent' communicator that we created has a lower CID than the parent comm. This can happen when using the hierarch collective communication module or for inter-communicators (since we make a duplicate of the original communicator). This is not a problem as long as the user calls MPI_Comm_free on the parent communicator. However, if the communicators are not freed by the user but released by Open MPI in MPI_Finalize, we walk through the list of still available communicators and free them one by one. Thus, local_comm is freed before the actual inter-communicator. However, the local_comm pointer in the inter communicator will still contain the 'previous' address of the local_comm and thus this will lead to a segmentation violation. In order to prevent that from happening, we increase the reference counter local_comm by one if its CID is lower than the parent. We cannot increase however its reference counter if the CID of local_comm is larger than the CID of the inter communicators, since a regular MPI_Comm_free would leave in that the case the local_comm hanging around and thus we would not recycle CID's properly, which was the reason and the cause for this trouble. This commit fixes tickets 2094 and 2166. Note however, that I want to close them manually, since a slightly different patch is required for the 1.4 series. This commit will have to be applied for the 1.5 series. And I will need a volunteer to review it. This commit was SVN r22671.
2010-02-20 02:45:30 +03:00
/* Release attributes. We do this now instead of during the
communicator destructor for 2 reasons:
1. The destructor will only NOT be called immediately during
ompi_comm_free() if the reference count is still greater
than zero at that point, meaning that there are ongoing
communications. However, pending communications will never
need attributes, so it's safe to release them directly here.
2. Releasing attributes in ompi_comm_free() enables us to check
the return status of the attribute delete functions. At
least one interpretation of the MPI standard (i.e., the one
of the Intel test suite) is that if any of the attribute
deletion functions fail, then MPI_COMM_FREE /
MPI_COMM_DISCONNECT should also fail. We can't do that if
we delay releasing the attributes -- we need to release the
attributes right away so that we can report the error right
away. */
if (NULL != (*comm)->c_keyhash) {
ret = ompi_attr_delete_all(COMM_ATTR, *comm, (*comm)->c_keyhash);
if (OMPI_SUCCESS != ret) {
return ret;
}
OBJ_RELEASE((*comm)->c_keyhash);
}
if ( OMPI_COMM_IS_INTER(*comm) ) {
ompi_comm_free (&(*comm)->c_local_comm);
}
/* Special case: if we are freeing the parent handle, then we need
to set our internal handle to the parent to be equal to
COMM_NULL. This is according to MPI-2:88-89. */
if (*comm == ompi_mpi_comm_parent && comm != &ompi_mpi_comm_parent) {
ompi_mpi_comm_parent = &ompi_mpi_comm_null.comm;
}
/* Release the communicator */
if ( OMPI_COMM_IS_DYNAMIC (*comm) ) {
ompi_comm_num_dyncomm --;
}
OBJ_RELEASE( (*comm) );
if ( is_extra_retain) {
/* This communicator has been marked as an "extra retain"
This commit fixes a bug on how to deal with the potential if a 'dependent' communicator that we created has a lower CID than the parent comm. This can happen when using the hierarch collective communication module or for inter-communicators (since we make a duplicate of the original communicator). This is not a problem as long as the user calls MPI_Comm_free on the parent communicator. However, if the communicators are not freed by the user but released by Open MPI in MPI_Finalize, we walk through the list of still available communicators and free them one by one. Thus, local_comm is freed before the actual inter-communicator. However, the local_comm pointer in the inter communicator will still contain the 'previous' address of the local_comm and thus this will lead to a segmentation violation. In order to prevent that from happening, we increase the reference counter local_comm by one if its CID is lower than the parent. We cannot increase however its reference counter if the CID of local_comm is larger than the CID of the inter communicators, since a regular MPI_Comm_free would leave in that the case the local_comm hanging around and thus we would not recycle CID's properly, which was the reason and the cause for this trouble. This commit fixes tickets 2094 and 2166. Note however, that I want to close them manually, since a slightly different patch is required for the 1.4 series. This commit will have to be applied for the 1.5 series. And I will need a volunteer to review it. This commit was SVN r22671.
2010-02-20 02:45:30 +03:00
* communicator. This can happen if a communicator creates
* 'dependent' subcommunicators (e.g. for inter
* communicators or when using hierarch collective
* module *and* the cid of the dependent communicator
* turned out to be lower than of the parent one.
* In that case, the reference counter has been increased
* by one more, in order to handle the scenario,
* that the user did not free the communicator.
* Note, that if we enter this routine, we can
* decrease the counter by one more therefore. However,
* in ompi_comm_finalize, we only used OBJ_RELEASE instead
* of ompi_comm_free(), and the increased reference counter
* makes sure that the pointer to the dependent communicator
* still contains a valid object.
*/
ompi_communicator_t *tmpcomm = (ompi_communicator_t *) opal_pointer_array_get_item(&ompi_mpi_communicators, cid);
This commit fixes a bug on how to deal with the potential if a 'dependent' communicator that we created has a lower CID than the parent comm. This can happen when using the hierarch collective communication module or for inter-communicators (since we make a duplicate of the original communicator). This is not a problem as long as the user calls MPI_Comm_free on the parent communicator. However, if the communicators are not freed by the user but released by Open MPI in MPI_Finalize, we walk through the list of still available communicators and free them one by one. Thus, local_comm is freed before the actual inter-communicator. However, the local_comm pointer in the inter communicator will still contain the 'previous' address of the local_comm and thus this will lead to a segmentation violation. In order to prevent that from happening, we increase the reference counter local_comm by one if its CID is lower than the parent. We cannot increase however its reference counter if the CID of local_comm is larger than the CID of the inter communicators, since a regular MPI_Comm_free would leave in that the case the local_comm hanging around and thus we would not recycle CID's properly, which was the reason and the cause for this trouble. This commit fixes tickets 2094 and 2166. Note however, that I want to close them manually, since a slightly different patch is required for the 1.4 series. This commit will have to be applied for the 1.5 series. And I will need a volunteer to review it. This commit was SVN r22671.
2010-02-20 02:45:30 +03:00
if ( NULL != tmpcomm ){
ompi_comm_free(&tmpcomm);
This commit fixes a bug on how to deal with the potential if a 'dependent' communicator that we created has a lower CID than the parent comm. This can happen when using the hierarch collective communication module or for inter-communicators (since we make a duplicate of the original communicator). This is not a problem as long as the user calls MPI_Comm_free on the parent communicator. However, if the communicators are not freed by the user but released by Open MPI in MPI_Finalize, we walk through the list of still available communicators and free them one by one. Thus, local_comm is freed before the actual inter-communicator. However, the local_comm pointer in the inter communicator will still contain the 'previous' address of the local_comm and thus this will lead to a segmentation violation. In order to prevent that from happening, we increase the reference counter local_comm by one if its CID is lower than the parent. We cannot increase however its reference counter if the CID of local_comm is larger than the CID of the inter communicators, since a regular MPI_Comm_free would leave in that the case the local_comm hanging around and thus we would not recycle CID's properly, which was the reason and the cause for this trouble. This commit fixes tickets 2094 and 2166. Note however, that I want to close them manually, since a slightly different patch is required for the 1.4 series. This commit will have to be applied for the 1.5 series. And I will need a volunteer to review it. This commit was SVN r22671.
2010-02-20 02:45:30 +03:00
}
}
*comm = MPI_COMM_NULL;
return OMPI_SUCCESS;
}
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/
ompi_proc_t **ompi_comm_get_rprocs ( ompi_communicator_t *local_comm,
ompi_communicator_t *bridge_comm,
int local_leader,
int remote_leader,
int tag,
int rsize)
{
MPI_Request req;
int rc;
int local_rank, local_size;
ompi_proc_t **rprocs=NULL;
int32_t size_len;
In comm.c, one of the few places where OMPI and ORTE interact, we have a clash of APIs -- MPI requires int's, but the ORTE DPS requires size_t's. Specifically, we need to orte_dps.unload(), which fills a size_t. We then need to PML send (i.e., MPI_Send) that value around. However, there's no such thing as MPI_SIZE_T as a datatype, and that would hose us in heterogeneous situations, anyway. So the compromise was to make ompi_sizet2int(), a function what does the [potenial] downcast. On 32 bit architectures, this is no big deal -- it's a simple assignment. On 64 bit architectures (or, more specifically, where sizeof(size_t) > sizeof(int)), it does the dowcast in a compiler-safe manner, and does a check to see if we truncated. If we truncated, in a developer build, we'll abort(). If this is not a developer build, print out a nasty warning. The rationale here is as followes: - this is a clash of the API's. There's unfortunately nothing that we can do about this at the moment. - hence, we have to do the downcast. - but we might as well be "safe" about it -- assuming that orte_dps.unload() never gives us back a value >sizeof(int) (which is a pretty safe assumption -- if we get that large of a value, we have other problems, or we're on fundamentally different types of hardware and I suspect a lot of the rest of the code base will have problems as well!), we should be able to downcast safely. - if there is a mistake in code somewhere such that: - we can't downcast safely (i.e., we legitmately have a size_t value that is too large for an int) - we truncate when the value should not have been that large the conversion function will detect this and print out an error. So we won't silently introduce any new errors into the code base -- they will be loud and obvious. - although comm.c is currently the only place where we need this, I suspect that there will be a small number of other places where similar situations occur. I intend to bring this right over to the trunk, so it was simpler to make this functionality be a subroutine so that we can use it elsewhere if/when necessary. Final note: src/attribute/attribute.c does something *similar* (downcasting when sizeof(void*) > sizeof(int), but is different enough that it would have been painful to make one unified interface. This does not rule it out for the future, however (especially if we find more places in the tree that need this kind of functionality). This commit was SVN r6246.
2005-07-01 01:30:18 +04:00
int int_len, rlen;
opal_buffer_t *sbuf=NULL, *rbuf=NULL;
void *sendbuf;
char *recvbuf;
ompi_proc_t **proc_list=NULL;
int i;
local_rank = ompi_comm_rank (local_comm);
local_size = ompi_comm_size (local_comm);
if (local_rank == local_leader) {
sbuf = OBJ_NEW(opal_buffer_t);
if (NULL == sbuf) {
rc = OMPI_ERROR;
goto err_exit;
}
if(OMPI_GROUP_IS_DENSE(local_comm->c_local_group)) {
rc = ompi_proc_pack(local_comm->c_local_group->grp_proc_pointers,
local_size, true, sbuf);
}
/* get the proc list for the sparse implementations */
else {
proc_list = (ompi_proc_t **) calloc (local_comm->c_local_group->grp_proc_count,
sizeof (ompi_proc_t *));
for(i=0 ; i<local_comm->c_local_group->grp_proc_count ; i++)
proc_list[i] = ompi_group_peer_lookup(local_comm->c_local_group,i);
rc = ompi_proc_pack (proc_list, local_size, true, sbuf);
}
if ( OMPI_SUCCESS != rc ) {
goto err_exit;
}
if (OPAL_SUCCESS != (rc = opal_dss.unload(sbuf, &sendbuf, &size_len))) {
goto err_exit;
In comm.c, one of the few places where OMPI and ORTE interact, we have a clash of APIs -- MPI requires int's, but the ORTE DPS requires size_t's. Specifically, we need to orte_dps.unload(), which fills a size_t. We then need to PML send (i.e., MPI_Send) that value around. However, there's no such thing as MPI_SIZE_T as a datatype, and that would hose us in heterogeneous situations, anyway. So the compromise was to make ompi_sizet2int(), a function what does the [potenial] downcast. On 32 bit architectures, this is no big deal -- it's a simple assignment. On 64 bit architectures (or, more specifically, where sizeof(size_t) > sizeof(int)), it does the dowcast in a compiler-safe manner, and does a check to see if we truncated. If we truncated, in a developer build, we'll abort(). If this is not a developer build, print out a nasty warning. The rationale here is as followes: - this is a clash of the API's. There's unfortunately nothing that we can do about this at the moment. - hence, we have to do the downcast. - but we might as well be "safe" about it -- assuming that orte_dps.unload() never gives us back a value >sizeof(int) (which is a pretty safe assumption -- if we get that large of a value, we have other problems, or we're on fundamentally different types of hardware and I suspect a lot of the rest of the code base will have problems as well!), we should be able to downcast safely. - if there is a mistake in code somewhere such that: - we can't downcast safely (i.e., we legitmately have a size_t value that is too large for an int) - we truncate when the value should not have been that large the conversion function will detect this and print out an error. So we won't silently introduce any new errors into the code base -- they will be loud and obvious. - although comm.c is currently the only place where we need this, I suspect that there will be a small number of other places where similar situations occur. I intend to bring this right over to the trunk, so it was simpler to make this functionality be a subroutine so that we can use it elsewhere if/when necessary. Final note: src/attribute/attribute.c does something *similar* (downcasting when sizeof(void*) > sizeof(int), but is different enough that it would have been painful to make one unified interface. This does not rule it out for the future, however (especially if we find more places in the tree that need this kind of functionality). This commit was SVN r6246.
2005-07-01 01:30:18 +04:00
}
/* send the remote_leader the length of the buffer */
rc = MCA_PML_CALL(irecv (&rlen, 1, MPI_INT, remote_leader, tag,
In comm.c, one of the few places where OMPI and ORTE interact, we have a clash of APIs -- MPI requires int's, but the ORTE DPS requires size_t's. Specifically, we need to orte_dps.unload(), which fills a size_t. We then need to PML send (i.e., MPI_Send) that value around. However, there's no such thing as MPI_SIZE_T as a datatype, and that would hose us in heterogeneous situations, anyway. So the compromise was to make ompi_sizet2int(), a function what does the [potenial] downcast. On 32 bit architectures, this is no big deal -- it's a simple assignment. On 64 bit architectures (or, more specifically, where sizeof(size_t) > sizeof(int)), it does the dowcast in a compiler-safe manner, and does a check to see if we truncated. If we truncated, in a developer build, we'll abort(). If this is not a developer build, print out a nasty warning. The rationale here is as followes: - this is a clash of the API's. There's unfortunately nothing that we can do about this at the moment. - hence, we have to do the downcast. - but we might as well be "safe" about it -- assuming that orte_dps.unload() never gives us back a value >sizeof(int) (which is a pretty safe assumption -- if we get that large of a value, we have other problems, or we're on fundamentally different types of hardware and I suspect a lot of the rest of the code base will have problems as well!), we should be able to downcast safely. - if there is a mistake in code somewhere such that: - we can't downcast safely (i.e., we legitmately have a size_t value that is too large for an int) - we truncate when the value should not have been that large the conversion function will detect this and print out an error. So we won't silently introduce any new errors into the code base -- they will be loud and obvious. - although comm.c is currently the only place where we need this, I suspect that there will be a small number of other places where similar situations occur. I intend to bring this right over to the trunk, so it was simpler to make this functionality be a subroutine so that we can use it elsewhere if/when necessary. Final note: src/attribute/attribute.c does something *similar* (downcasting when sizeof(void*) > sizeof(int), but is different enough that it would have been painful to make one unified interface. This does not rule it out for the future, however (especially if we find more places in the tree that need this kind of functionality). This commit was SVN r6246.
2005-07-01 01:30:18 +04:00
bridge_comm, &req ));
if ( OMPI_SUCCESS != rc ) {
goto err_exit;
}
int_len = (int)size_len;
rc = MCA_PML_CALL(send (&int_len, 1, MPI_INT, remote_leader, tag,
In comm.c, one of the few places where OMPI and ORTE interact, we have a clash of APIs -- MPI requires int's, but the ORTE DPS requires size_t's. Specifically, we need to orte_dps.unload(), which fills a size_t. We then need to PML send (i.e., MPI_Send) that value around. However, there's no such thing as MPI_SIZE_T as a datatype, and that would hose us in heterogeneous situations, anyway. So the compromise was to make ompi_sizet2int(), a function what does the [potenial] downcast. On 32 bit architectures, this is no big deal -- it's a simple assignment. On 64 bit architectures (or, more specifically, where sizeof(size_t) > sizeof(int)), it does the dowcast in a compiler-safe manner, and does a check to see if we truncated. If we truncated, in a developer build, we'll abort(). If this is not a developer build, print out a nasty warning. The rationale here is as followes: - this is a clash of the API's. There's unfortunately nothing that we can do about this at the moment. - hence, we have to do the downcast. - but we might as well be "safe" about it -- assuming that orte_dps.unload() never gives us back a value >sizeof(int) (which is a pretty safe assumption -- if we get that large of a value, we have other problems, or we're on fundamentally different types of hardware and I suspect a lot of the rest of the code base will have problems as well!), we should be able to downcast safely. - if there is a mistake in code somewhere such that: - we can't downcast safely (i.e., we legitmately have a size_t value that is too large for an int) - we truncate when the value should not have been that large the conversion function will detect this and print out an error. So we won't silently introduce any new errors into the code base -- they will be loud and obvious. - although comm.c is currently the only place where we need this, I suspect that there will be a small number of other places where similar situations occur. I intend to bring this right over to the trunk, so it was simpler to make this functionality be a subroutine so that we can use it elsewhere if/when necessary. Final note: src/attribute/attribute.c does something *similar* (downcasting when sizeof(void*) > sizeof(int), but is different enough that it would have been painful to make one unified interface. This does not rule it out for the future, however (especially if we find more places in the tree that need this kind of functionality). This commit was SVN r6246.
2005-07-01 01:30:18 +04:00
MCA_PML_BASE_SEND_STANDARD, bridge_comm ));
if ( OMPI_SUCCESS != rc ) {
goto err_exit;
}
rc = ompi_request_wait_all ( 1, &req, MPI_STATUS_IGNORE );
if ( OMPI_SUCCESS != rc ) {
goto err_exit;
}
}
/* broadcast buffer length to all processes in local_comm */
rc = local_comm->c_coll.coll_bcast( &rlen, 1, MPI_INT,
local_leader, local_comm,
local_comm->c_coll.coll_bcast_module );
if ( OMPI_SUCCESS != rc ) {
goto err_exit;
}
/* Allocate temporary buffer */
recvbuf = (char *)malloc(rlen);
if ( NULL == recvbuf ) {
goto err_exit;
}
if ( local_rank == local_leader ) {
/* local leader exchange name lists */
rc = MCA_PML_CALL(irecv (recvbuf, rlen, MPI_BYTE, remote_leader, tag,
bridge_comm, &req ));
if ( OMPI_SUCCESS != rc ) {
goto err_exit;
}
rc = MCA_PML_CALL(send(sendbuf, int_len, MPI_BYTE, remote_leader, tag,
MCA_PML_BASE_SEND_STANDARD, bridge_comm ));
if ( OMPI_SUCCESS != rc ) {
goto err_exit;
}
rc = ompi_request_wait_all ( 1, &req, MPI_STATUS_IGNORE );
if ( OMPI_SUCCESS != rc ) {
goto err_exit;
}
OBJ_RELEASE(sbuf);
}
/* broadcast name list to all proceses in local_comm */
rc = local_comm->c_coll.coll_bcast( recvbuf, rlen, MPI_BYTE,
local_leader, local_comm,
local_comm->c_coll.coll_bcast_module);
if ( OMPI_SUCCESS != rc ) {
goto err_exit;
}
rbuf = OBJ_NEW(opal_buffer_t);
if (NULL == rbuf) {
rc = OMPI_ERROR;
goto err_exit;
}
if (OMPI_SUCCESS != (rc = opal_dss.load(rbuf, recvbuf, rlen))) {
goto err_exit;
}
/* decode the names into a proc-list */
rc = ompi_proc_unpack(rbuf, rsize, &rprocs, true, NULL, NULL);
OBJ_RELEASE(rbuf);
/* And now add the information into the database */
/* Store the remote processes into the opal_db */
if (OMPI_SUCCESS != (rc = MCA_PML_CALL(add_procs(rprocs, rsize)))) {
OMPI_ERROR_LOG(rc);
goto err_exit;
}
err_exit:
/* rprocs isn't freed unless we have an error,
since it is used in the communicator */
if ( OMPI_SUCCESS != rc ) {
opal_output(0, "%d: Error in ompi_get_rprocs\n", local_rank);
if ( NULL != rprocs ) {
free ( rprocs );
rprocs=NULL;
}
}
/* make sure the buffers have been released */
if (NULL != sbuf) {
OBJ_RELEASE(sbuf);
}
if (NULL != rbuf) {
OBJ_RELEASE(rbuf);
}
if ( NULL != proc_list ) {
free ( proc_list );
}
return rprocs;
}
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/
/**
* This routine verifies, whether local_group and remote group are overlapping
* in intercomm_create
*/
int ompi_comm_overlapping_groups (int size, ompi_proc_t **lprocs,
int rsize, ompi_proc_t ** rprocs)
{
int rc=OMPI_SUCCESS;
int i,j;
for (i=0; i<size; i++) {
for ( j=0; j<rsize; j++) {
if ( lprocs[i] == rprocs[j] ) {
rc = MPI_ERR_COMM;
return rc;
}
}
}
return rc;
}
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/
int ompi_comm_determine_first ( ompi_communicator_t *intercomm, int high )
{
int flag, rhigh;
int rank, rsize;
int *rcounts;
int *rdisps;
int scount=0;
int rc;
ompi_proc_t *ourproc, *theirproc;
ompi_rte_cmp_bitmask_t mask;
rank = ompi_comm_rank (intercomm);
rsize= ompi_comm_remote_size (intercomm);
rdisps = (int *) calloc ( rsize, sizeof(int));
rcounts = (int *) calloc ( rsize, sizeof(int));
if ( NULL == rdisps || NULL == rcounts ){
return OMPI_ERR_OUT_OF_RESOURCE;
}
rcounts[0] = 1;
if ( 0 == rank ) {
scount = 1;
}
rc = intercomm->c_coll.coll_allgatherv(&high, scount, MPI_INT,
&rhigh, rcounts, rdisps,
MPI_INT, intercomm,
intercomm->c_coll.coll_allgatherv_module);
if ( rc != OMPI_SUCCESS ) {
flag = MPI_UNDEFINED;
}
if ( NULL != rdisps ) {
free ( rdisps );
}
if ( NULL != rcounts ) {
free ( rcounts );
}
/* This is the logic for determining who is first, who is second */
if ( high && !rhigh ) {
flag = false;
}
else if ( !high && rhigh ) {
flag = true;
}
else {
ourproc = ompi_group_peer_lookup(intercomm->c_local_group,0);
theirproc = ompi_group_peer_lookup(intercomm->c_remote_group,0);
mask = OMPI_RTE_CMP_JOBID | OMPI_RTE_CMP_VPID;
rc = ompi_rte_compare_name_fields(mask, &(ourproc->proc_name), &(theirproc->proc_name));
if ( 0 > rc ) {
flag = true;
}
else {
flag = false;
}
}
return flag;
}
/********************************************************************************/
/********************************************************************************/
/********************************************************************************/
int ompi_comm_dump ( ompi_communicator_t *comm )
{
opal_output(0, "Dumping information for comm_cid %d\n", comm->c_contextid);
opal_output(0," f2c index:%d cube_dim: %d\n", comm->c_f_to_c_index,
comm->c_cube_dim);
opal_output(0," Local group: size = %d my_rank = %d\n",
comm->c_local_group->grp_proc_count,
comm->c_local_group->grp_my_rank );
opal_output(0," Communicator is:");
/* Display flags */
if ( OMPI_COMM_IS_INTER(comm) )
opal_output(0," inter-comm,");
if ( OMPI_COMM_IS_CART(comm))
opal_output(0," topo-cart");
else if ( OMPI_COMM_IS_GRAPH(comm))
opal_output(0," topo-graph");
else if ( OMPI_COMM_IS_DIST_GRAPH(comm))
opal_output(0," topo-dist-graph");
opal_output(0,"\n");
if (OMPI_COMM_IS_INTER(comm)) {
opal_output(0," Remote group size:%d\n", comm->c_remote_group->grp_proc_count);
}
return OMPI_SUCCESS;
}
/********************************************************************************/
/********************************************************************************/
/********************************************************************************/
/* static functions */
/*
** rankkeygidcompare() compares a tuple of (rank,key,gid) producing
** sorted lists that match the rules needed for a MPI_Comm_split
*/
static int rankkeycompare (const void *p, const void *q)
{
int *a, *b;
/* ranks at [0] key at [1] */
/* i.e. we cast and just compare the keys and then the original ranks.. */
a = (int*)p;
b = (int*)q;
/* simple tests are those where the keys are different */
if (a[1] < b[1]) {
return (-1);
}
if (a[1] > b[1]) {
return (1);
}
/* ok, if the keys are the same then we check the original ranks */
if (a[1] == b[1]) {
if (a[0] < b[0]) {
return (-1);
}
if (a[0] == b[0]) {
return (0);
}
if (a[0] > b[0]) {
return (1);
}
}
return ( 0 );
}
/***********************************************************************
- massive change for module<-->component name fixes throughout the code base. - many (most) mca type names have "component" or "module" in them, as relevant, just to further distinguish the difference between component data/actions and module data/actions. All developers are encouraged to perpetuate this convention when you create types that are specific to a framework, component, or module - did very little to entire framework (just the basics to make it compile) because it's just about to be almost entirely replaced - ditto for io / romio - did not work on elan or ib components; have to commit and then convert those on a different machine with the right libraries and headers - renamed a bunch of *_module.c files to *_component.c and *module*c to *component*c (a few still remain, e.g., ptl/ib, ptl/elan, etc.) - modified autogen/configure/build process to match new filenames (e.g., output static-components.h instead of static-modules.h) - removed DOS-style cr/lf stuff in ns/ns.h - added newline to end of file src/util/numtostr.h - removed some redundant error checking in the top-level topo functions - added a few {} here and there where people "forgot" to put them in for 1 line blocks ;-) - removed a bunch of MPI_* types from mca header files (replaced with corresponding ompi_* types) - all the ptl components had version numbers in their structs; removed - converted a few more elements in the MCA base to use the OBJ interface -- removed some old manual reference counting kruft This commit was SVN r1830.
2004-08-02 04:24:22 +04:00
* Counterpart of MPI_Cart/Graph_create. This will be called from the
* top level MPI. The condition for INTER communicator is already
* checked by the time this has been invoked. This function should do
* somewhat the same things which ompi_comm_create does. It will
* however select a component for topology and then call the
* cart_create on that component so that it can re-arrange the proc
* structure as required (if the reorder flag is true). It will then
* use this proc structure to create the communicator using
* ompi_comm_set.
*/
/**
* Take an almost complete communicator and reserve the CID as well
* as activate it (initialize the collective and the topologies).
*/
int ompi_comm_enable(ompi_communicator_t *old_comm,
ompi_communicator_t *new_comm,
int new_rank,
int num_procs,
ompi_proc_t** topo_procs)
{
int ret = OMPI_SUCCESS;
/* Determine context id. It is identical to f_2_c_handle */
ret = ompi_comm_nextcid ( new_comm, /* new communicator */
old_comm, /* old comm */
NULL, /* bridge comm */
NULL, /* local leader */
NULL, /* remote_leader */
OMPI_COMM_CID_INTRA, /* mode */
-1 ); /* send first, doesn't matter */
if (OMPI_SUCCESS != ret) {
/* something wrong happened while setting the communicator */
goto complete_and_return;
}
/* Now, the topology module has been selected and the group
- massive change for module<-->component name fixes throughout the code base. - many (most) mca type names have "component" or "module" in them, as relevant, just to further distinguish the difference between component data/actions and module data/actions. All developers are encouraged to perpetuate this convention when you create types that are specific to a framework, component, or module - did very little to entire framework (just the basics to make it compile) because it's just about to be almost entirely replaced - ditto for io / romio - did not work on elan or ib components; have to commit and then convert those on a different machine with the right libraries and headers - renamed a bunch of *_module.c files to *_component.c and *module*c to *component*c (a few still remain, e.g., ptl/ib, ptl/elan, etc.) - modified autogen/configure/build process to match new filenames (e.g., output static-components.h instead of static-modules.h) - removed DOS-style cr/lf stuff in ns/ns.h - added newline to end of file src/util/numtostr.h - removed some redundant error checking in the top-level topo functions - added a few {} here and there where people "forgot" to put them in for 1 line blocks ;-) - removed a bunch of MPI_* types from mca header files (replaced with corresponding ompi_* types) - all the ptl components had version numbers in their structs; removed - converted a few more elements in the MCA base to use the OBJ interface -- removed some old manual reference counting kruft This commit was SVN r1830.
2004-08-02 04:24:22 +04:00
* which has the topology information has been created. All we
* need to do now is to fill the rest of the information into the
* communicator. The following steps are not just similar to
* ompi_comm_set, but are actually the same */
ret = ompi_comm_fill_rest(new_comm, /* the communicator */
num_procs, /* local size */
topo_procs, /* process structure */
new_rank, /* rank of the process */
old_comm->error_handler); /* error handler */
if (OMPI_SUCCESS != ret) {
/* something wrong happened while setting the communicator */
goto complete_and_return;
}
so here is what happens: in the v1.2 series the cid's could never go above the max. allowed for a particular pml. Because of that, pml_add_comm never checked for the cid, and in fact pml_add_comm was called in comm_set, which is *before* we knew the cid. in the v1.3 series (and trunk) we check now the cid to detect overflow, and because of that pml_add_comm has been moved *after* the cid allocation routine, namely into the comm_activate routine. in the v1.2 series, the comm_activate contained a synchronization step of the old communicator in order to prevent incoming fragments on the new communicator, with the main problem being that the allreduce in the communicator allocation finished at different times on different processes, and thus, this scenario could and did really occur. in the v1.3 series, the comm_activate does not contain the synchronization step anymore, since we introduced the new queue for fragments with unknown cid. The problem is however, that whether a fragment is known or not is decided by using ompi_comm_lookup(), which will return something useful as soon as the cid allocation finished, even before pml_add_comm has been called. So there is a small time gap where we will not post a message into queue for unknown cid's, but we can also not look up the process structure belonging to the rank in that comm ( that is in pml_ob1_match_recv_frag or something like that). The current fix reintroduces the synchronization step in comm_activate, and ensures that no fragment can be received for a new communicator before the synchronization occurs , and thus comm_nextcid() and pml_add_comm has been called. It seems to be the safest and easiest way for now. Welcome back, v1.2. This commit was SVN r21970.
2009-09-17 18:37:02 +04:00
ret = ompi_comm_activate( &new_comm, /* new communicator */
old_comm, /* old comm */
NULL, /* bridge comm */
NULL, /* local leader */
NULL, /* remote_leader */
so here is what happens: in the v1.2 series the cid's could never go above the max. allowed for a particular pml. Because of that, pml_add_comm never checked for the cid, and in fact pml_add_comm was called in comm_set, which is *before* we knew the cid. in the v1.3 series (and trunk) we check now the cid to detect overflow, and because of that pml_add_comm has been moved *after* the cid allocation routine, namely into the comm_activate routine. in the v1.2 series, the comm_activate contained a synchronization step of the old communicator in order to prevent incoming fragments on the new communicator, with the main problem being that the allreduce in the communicator allocation finished at different times on different processes, and thus, this scenario could and did really occur. in the v1.3 series, the comm_activate does not contain the synchronization step anymore, since we introduced the new queue for fragments with unknown cid. The problem is however, that whether a fragment is known or not is decided by using ompi_comm_lookup(), which will return something useful as soon as the cid allocation finished, even before pml_add_comm has been called. So there is a small time gap where we will not post a message into queue for unknown cid's, but we can also not look up the process structure belonging to the rank in that comm ( that is in pml_ob1_match_recv_frag or something like that). The current fix reintroduces the synchronization step in comm_activate, and ensures that no fragment can be received for a new communicator before the synchronization occurs , and thus comm_nextcid() and pml_add_comm has been called. It seems to be the safest and easiest way for now. Welcome back, v1.2. This commit was SVN r21970.
2009-09-17 18:37:02 +04:00
OMPI_COMM_CID_INTRA, /* mode */
-1 ); /* send first, doesn't matter */
so here is what happens: in the v1.2 series the cid's could never go above the max. allowed for a particular pml. Because of that, pml_add_comm never checked for the cid, and in fact pml_add_comm was called in comm_set, which is *before* we knew the cid. in the v1.3 series (and trunk) we check now the cid to detect overflow, and because of that pml_add_comm has been moved *after* the cid allocation routine, namely into the comm_activate routine. in the v1.2 series, the comm_activate contained a synchronization step of the old communicator in order to prevent incoming fragments on the new communicator, with the main problem being that the allreduce in the communicator allocation finished at different times on different processes, and thus, this scenario could and did really occur. in the v1.3 series, the comm_activate does not contain the synchronization step anymore, since we introduced the new queue for fragments with unknown cid. The problem is however, that whether a fragment is known or not is decided by using ompi_comm_lookup(), which will return something useful as soon as the cid allocation finished, even before pml_add_comm has been called. So there is a small time gap where we will not post a message into queue for unknown cid's, but we can also not look up the process structure belonging to the rank in that comm ( that is in pml_ob1_match_recv_frag or something like that). The current fix reintroduces the synchronization step in comm_activate, and ensures that no fragment can be received for a new communicator before the synchronization occurs , and thus comm_nextcid() and pml_add_comm has been called. It seems to be the safest and easiest way for now. Welcome back, v1.2. This commit was SVN r21970.
2009-09-17 18:37:02 +04:00
if (OMPI_SUCCESS != ret) {
/* something wrong happened while setting the communicator */
goto complete_and_return;
}
complete_and_return:
return ret;
}
static int ompi_comm_fill_rest(ompi_communicator_t *comm,
int num_procs,
ompi_proc_t **proc_pointers,
int my_rank,
ompi_errhandler_t *errh)
- massive change for module<-->component name fixes throughout the code base. - many (most) mca type names have "component" or "module" in them, as relevant, just to further distinguish the difference between component data/actions and module data/actions. All developers are encouraged to perpetuate this convention when you create types that are specific to a framework, component, or module - did very little to entire framework (just the basics to make it compile) because it's just about to be almost entirely replaced - ditto for io / romio - did not work on elan or ib components; have to commit and then convert those on a different machine with the right libraries and headers - renamed a bunch of *_module.c files to *_component.c and *module*c to *component*c (a few still remain, e.g., ptl/ib, ptl/elan, etc.) - modified autogen/configure/build process to match new filenames (e.g., output static-components.h instead of static-modules.h) - removed DOS-style cr/lf stuff in ns/ns.h - added newline to end of file src/util/numtostr.h - removed some redundant error checking in the top-level topo functions - added a few {} here and there where people "forgot" to put them in for 1 line blocks ;-) - removed a bunch of MPI_* types from mca header files (replaced with corresponding ompi_* types) - all the ptl components had version numbers in their structs; removed - converted a few more elements in the MCA base to use the OBJ interface -- removed some old manual reference counting kruft This commit was SVN r1830.
2004-08-02 04:24:22 +04:00
{
/* properly decrement the ref counts on the groups.
We are doing this because this function is sort of a redo
of what is done in comm.c. No need to decrement the ref
count on the proc pointers
This is just a quick fix, and will be looking for a
better solution */
OBJ_RELEASE( comm->c_local_group );
OBJ_RELEASE( comm->c_local_group );
/* allocate a group structure for the new communicator */
comm->c_local_group = ompi_group_allocate(num_procs);
/* free the malloced proc pointers */
free(comm->c_local_group->grp_proc_pointers);
/* set the group information */
comm->c_local_group->grp_proc_pointers = proc_pointers;
/* set the remote group to be the same as local group */
comm->c_remote_group = comm->c_local_group;
OBJ_RETAIN( comm->c_remote_group );
/* retain these proc pointers */
ompi_group_increment_proc_count(comm->c_local_group);
/* set the rank information */
comm->c_local_group->grp_my_rank = my_rank;
comm->c_my_rank = my_rank;
if( MPI_UNDEFINED != my_rank ) {
/* verify whether to set the flag, that this comm
contains process from more than one jobid. */
ompi_dpm.mark_dyncomm (comm);
}
/* set the error handler */
comm->error_handler = errh;
OBJ_RETAIN (comm->error_handler);
/* set name for debugging purposes */
/* there is no cid at this stage ... make this right and make edgars
* code call this function and remove dupli cde
*/
snprintf (comm->c_name, MPI_MAX_OBJECT_NAME, "MPI_COMMUNICATOR %d",
comm->c_contextid);
/* determine the cube dimensions */
comm->c_cube_dim = opal_cube_dim(comm->c_local_group->grp_proc_count);
return OMPI_SUCCESS;
}
static int ompi_comm_copy_topo(ompi_communicator_t *oldcomm,
ompi_communicator_t *newcomm)
{
if( NULL == oldcomm->c_topo )
return OMPI_ERR_NOT_FOUND;
newcomm->c_topo = oldcomm->c_topo;
OBJ_RETAIN(newcomm->c_topo);
newcomm->c_flags |= newcomm->c_topo->type;
return OMPI_SUCCESS;
}