Blame src/mpi/topo/dist_gr_create_adj.c

Packit Service c5cf8c
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
Packit Service c5cf8c
/*
Packit Service c5cf8c
 *
Packit Service c5cf8c
 *  (C) 2009 by Argonne National Laboratory.
Packit Service c5cf8c
 *      See COPYRIGHT in top-level directory.
Packit Service c5cf8c
 */
Packit Service c5cf8c
Packit Service c5cf8c
#include "mpiimpl.h"
Packit Service c5cf8c
Packit Service c5cf8c
/* -- Begin Profiling Symbol Block for routine MPI_Dist_graph_create_adjacent */
Packit Service c5cf8c
#if defined(HAVE_PRAGMA_WEAK)
Packit Service c5cf8c
#pragma weak MPI_Dist_graph_create_adjacent = PMPI_Dist_graph_create_adjacent
Packit Service c5cf8c
#elif defined(HAVE_PRAGMA_HP_SEC_DEF)
Packit Service c5cf8c
#pragma _HP_SECONDARY_DEF PMPI_Dist_graph_create_adjacent  MPI_Dist_graph_create_adjacent
Packit Service c5cf8c
#elif defined(HAVE_PRAGMA_CRI_DUP)
Packit Service c5cf8c
#pragma _CRI duplicate MPI_Dist_graph_create_adjacent as PMPI_Dist_graph_create_adjacent
Packit Service c5cf8c
#elif defined(HAVE_WEAK_ATTRIBUTE)
Packit Service c5cf8c
int MPI_Dist_graph_create_adjacent(MPI_Comm comm_old, int indegree, const int sources[],
Packit Service c5cf8c
                                   const int sourceweights[], int outdegree,
Packit Service c5cf8c
                                   const int destinations[], const int destweights[],
Packit Service c5cf8c
                                   MPI_Info info, int reorder, MPI_Comm * comm_dist_graph)
Packit Service c5cf8c
    __attribute__ ((weak, alias("PMPI_Dist_graph_create_adjacent")));
Packit Service c5cf8c
#endif
Packit Service c5cf8c
/* -- End Profiling Symbol Block */
Packit Service c5cf8c
Packit Service c5cf8c
/* Define MPICH_MPI_FROM_PMPI if weak symbols are not supported to build
Packit Service c5cf8c
   the MPI routines */
Packit Service c5cf8c
#ifndef MPICH_MPI_FROM_PMPI
Packit Service c5cf8c
#undef MPI_Dist_graph_create_adjacent
Packit Service c5cf8c
#define MPI_Dist_graph_create_adjacent PMPI_Dist_graph_create_adjacent
Packit Service c5cf8c
/* any utility functions should go here, usually prefixed with PMPI_LOCAL to
Packit Service c5cf8c
 * correctly handle weak symbols and the profiling interface */
Packit Service c5cf8c
#endif
Packit Service c5cf8c
Packit Service c5cf8c
#undef FUNCNAME
Packit Service c5cf8c
#define FUNCNAME MPI_Dist_graph_create_adjacent
Packit Service c5cf8c
#undef FCNAME
Packit Service c5cf8c
#define FCNAME MPL_QUOTE(FUNCNAME)
Packit Service c5cf8c
/*@
Packit Service c5cf8c
MPI_Dist_graph_create_adjacent - returns a handle to a new communicator to
Packit Service c5cf8c
which the distributed graph topology information is attached.
Packit Service c5cf8c
Packit Service c5cf8c
Input Parameters:
Packit Service c5cf8c
+ comm_old - input communicator (handle)
Packit Service c5cf8c
. indegree - size of sources and sourceweights arrays (non-negative integer)
Packit Service c5cf8c
. sources - ranks of processes for which the calling process is a
Packit Service c5cf8c
            destination (array of non-negative integers)
Packit Service c5cf8c
. sourceweights - weights of the edges into the calling
Packit Service c5cf8c
                  process (array of non-negative integers or MPI_UNWEIGHTED)
Packit Service c5cf8c
. outdegree - size of destinations and destweights arrays (non-negative integer)
Packit Service c5cf8c
. destinations - ranks of processes for which the calling process is a
Packit Service c5cf8c
                 source (array of non-negative integers)
Packit Service c5cf8c
. destweights - weights of the edges out of the calling process
Packit Service c5cf8c
                (array of non-negative integers or MPI_UNWEIGHTED)
Packit Service c5cf8c
. info - hints on optimization and interpretation of weights (handle)
Packit Service c5cf8c
- reorder - the ranks may be reordered (true) or not (false) (logical)
Packit Service c5cf8c
Packit Service c5cf8c
Output Parameters:
Packit Service c5cf8c
. comm_dist_graph - communicator with distributed graph topology (handle)
Packit Service c5cf8c
Packit Service c5cf8c
.N ThreadSafe
Packit Service c5cf8c
Packit Service c5cf8c
.N Fortran
Packit Service c5cf8c
Packit Service c5cf8c
.N Errors
Packit Service c5cf8c
.N MPI_SUCCESS
Packit Service c5cf8c
.N MPI_ERR_ARG
Packit Service c5cf8c
.N MPI_ERR_OTHER
Packit Service c5cf8c
@*/
Packit Service c5cf8c
int MPI_Dist_graph_create_adjacent(MPI_Comm comm_old,
Packit Service c5cf8c
                                   int indegree, const int sources[],
Packit Service c5cf8c
                                   const int sourceweights[],
Packit Service c5cf8c
                                   int outdegree, const int destinations[],
Packit Service c5cf8c
                                   const int destweights[],
Packit Service c5cf8c
                                   MPI_Info info, int reorder, MPI_Comm * comm_dist_graph)
Packit Service c5cf8c
{
Packit Service c5cf8c
    int mpi_errno = MPI_SUCCESS;
Packit Service c5cf8c
    MPIR_Comm *comm_ptr = NULL;
Packit Service c5cf8c
    MPIR_Comm *comm_dist_graph_ptr = NULL;
Packit Service c5cf8c
    MPIR_Topology *topo_ptr = NULL;
Packit Service c5cf8c
    MPII_Dist_graph_topology *dist_graph_ptr = NULL;
Packit Service c5cf8c
    MPIR_CHKPMEM_DECL(5);
Packit Service c5cf8c
    MPIR_FUNC_TERSE_STATE_DECL(MPID_STATE_MPI_DIST_GRAPH_CREATE_ADJACENT);
Packit Service c5cf8c
Packit Service c5cf8c
    MPIR_ERRTEST_INITIALIZED_ORDIE();
Packit Service c5cf8c
Packit Service c5cf8c
    MPID_THREAD_CS_ENTER(GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX);
Packit Service c5cf8c
    MPIR_FUNC_TERSE_ENTER(MPID_STATE_MPI_DIST_GRAPH_CREATE_ADJACENT);
Packit Service c5cf8c
Packit Service c5cf8c
    /* Validate parameters, especially handles needing to be converted */
Packit Service c5cf8c
#ifdef HAVE_ERROR_CHECKING
Packit Service c5cf8c
    {
Packit Service c5cf8c
        MPID_BEGIN_ERROR_CHECKS;
Packit Service c5cf8c
        {
Packit Service c5cf8c
            MPIR_ERRTEST_COMM(comm_old, mpi_errno);
Packit Service c5cf8c
            MPIR_ERRTEST_INFO_OR_NULL(info, mpi_errno);
Packit Service c5cf8c
        }
Packit Service c5cf8c
        MPID_END_ERROR_CHECKS;
Packit Service c5cf8c
    }
Packit Service c5cf8c
#endif
Packit Service c5cf8c
Packit Service c5cf8c
    /* Convert MPI object handles to object pointers */
Packit Service c5cf8c
    MPIR_Comm_get_ptr(comm_old, comm_ptr);
Packit Service c5cf8c
Packit Service c5cf8c
    /* Validate parameters and objects (post conversion) */
Packit Service c5cf8c
#ifdef HAVE_ERROR_CHECKING
Packit Service c5cf8c
    {
Packit Service c5cf8c
        MPID_BEGIN_ERROR_CHECKS;
Packit Service c5cf8c
        {
Packit Service c5cf8c
            /* Validate comm_ptr */
Packit Service c5cf8c
            MPIR_Comm_valid_ptr(comm_ptr, mpi_errno, FALSE);
Packit Service c5cf8c
            if (mpi_errno != MPI_SUCCESS)
Packit Service c5cf8c
                goto fn_fail;
Packit Service c5cf8c
            /* If comm_ptr is not valid, it will be reset to null */
Packit Service c5cf8c
            if (comm_ptr) {
Packit Service c5cf8c
                MPIR_ERRTEST_COMM_INTRA(comm_ptr, mpi_errno);
Packit Service c5cf8c
            }
Packit Service c5cf8c
Packit Service c5cf8c
            MPIR_ERRTEST_ARGNEG(indegree, "indegree", mpi_errno);
Packit Service c5cf8c
            MPIR_ERRTEST_ARGNEG(outdegree, "outdegree", mpi_errno);
Packit Service c5cf8c
Packit Service c5cf8c
            if (indegree > 0) {
Packit Service c5cf8c
                MPIR_ERRTEST_ARGNULL(sources, "sources", mpi_errno);
Packit Service c5cf8c
                if (sourceweights == MPI_UNWEIGHTED && destweights != MPI_UNWEIGHTED) {
Packit Service c5cf8c
                    MPIR_ERR_SET(mpi_errno, MPI_ERR_TOPOLOGY, "**unweightedboth");
Packit Service c5cf8c
                    goto fn_fail;
Packit Service c5cf8c
                }
Packit Service c5cf8c
                /* TODO check ranges for array elements too (**argarrayneg / **rankarray) */
Packit Service c5cf8c
            }
Packit Service c5cf8c
            if (outdegree > 0) {
Packit Service c5cf8c
                MPIR_ERRTEST_ARGNULL(destinations, "destinations", mpi_errno);
Packit Service c5cf8c
                if (destweights == MPI_UNWEIGHTED && sourceweights != MPI_UNWEIGHTED) {
Packit Service c5cf8c
                    MPIR_ERR_SET(mpi_errno, MPI_ERR_TOPOLOGY, "**unweightedboth");
Packit Service c5cf8c
                    goto fn_fail;
Packit Service c5cf8c
                }
Packit Service c5cf8c
            }
Packit Service c5cf8c
            MPIR_ERRTEST_ARGNULL(comm_dist_graph, "comm_dist_graph", mpi_errno);
Packit Service c5cf8c
        }
Packit Service c5cf8c
        MPID_END_ERROR_CHECKS;
Packit Service c5cf8c
    }
Packit Service c5cf8c
#endif /* HAVE_ERROR_CHECKING */
Packit Service c5cf8c
Packit Service c5cf8c
    /* ... body of routine ...  */
Packit Service c5cf8c
Packit Service c5cf8c
    /* Implementation based on Torsten Hoefler's reference implementation
Packit Service c5cf8c
     * attached to MPI-2.2 ticket #33. */
Packit Service c5cf8c
    *comm_dist_graph = MPI_COMM_NULL;
Packit Service c5cf8c
Packit Service c5cf8c
    /* following the spirit of the old topo interface, attributes do not
Packit Service c5cf8c
     * propagate to the new communicator (see MPI-2.1 pp. 243 line 11) */
Packit Service c5cf8c
    mpi_errno = MPII_Comm_copy(comm_ptr, comm_ptr->local_size, &comm_dist_graph_ptr);
Packit Service c5cf8c
    if (mpi_errno)
Packit Service c5cf8c
        MPIR_ERR_POP(mpi_errno);
Packit Service c5cf8c
Packit Service c5cf8c
    /* Create the topology structure */
Packit Service c5cf8c
    MPIR_CHKPMEM_MALLOC(topo_ptr, MPIR_Topology *, sizeof(MPIR_Topology), mpi_errno, "topo_ptr",
Packit Service c5cf8c
                        MPL_MEM_COMM);
Packit Service c5cf8c
    topo_ptr->kind = MPI_DIST_GRAPH;
Packit Service c5cf8c
    dist_graph_ptr = &topo_ptr->topo.dist_graph;
Packit Service c5cf8c
    dist_graph_ptr->indegree = indegree;
Packit Service c5cf8c
    dist_graph_ptr->in = NULL;
Packit Service c5cf8c
    dist_graph_ptr->in_weights = NULL;
Packit Service c5cf8c
    dist_graph_ptr->outdegree = outdegree;
Packit Service c5cf8c
    dist_graph_ptr->out = NULL;
Packit Service c5cf8c
    dist_graph_ptr->out_weights = NULL;
Packit Service c5cf8c
    dist_graph_ptr->is_weighted = (sourceweights != MPI_UNWEIGHTED);
Packit Service c5cf8c
Packit Service c5cf8c
    MPIR_CHKPMEM_MALLOC(dist_graph_ptr->in, int *, indegree * sizeof(int), mpi_errno,
Packit Service c5cf8c
                        "dist_graph_ptr->in", MPL_MEM_COMM);
Packit Service c5cf8c
    MPIR_CHKPMEM_MALLOC(dist_graph_ptr->out, int *, outdegree * sizeof(int), mpi_errno,
Packit Service c5cf8c
                        "dist_graph_ptr->out", MPL_MEM_COMM);
Packit Service c5cf8c
    MPIR_Memcpy(dist_graph_ptr->in, sources, indegree * sizeof(int));
Packit Service c5cf8c
    MPIR_Memcpy(dist_graph_ptr->out, destinations, outdegree * sizeof(int));
Packit Service c5cf8c
Packit Service c5cf8c
    if (dist_graph_ptr->is_weighted) {
Packit Service c5cf8c
        MPIR_CHKPMEM_MALLOC(dist_graph_ptr->in_weights, int *, indegree * sizeof(int), mpi_errno,
Packit Service c5cf8c
                            "dist_graph_ptr->in_weights", MPL_MEM_COMM);
Packit Service c5cf8c
        MPIR_CHKPMEM_MALLOC(dist_graph_ptr->out_weights, int *, outdegree * sizeof(int), mpi_errno,
Packit Service c5cf8c
                            "dist_graph_ptr->out_weights", MPL_MEM_COMM);
Packit Service c5cf8c
        MPIR_Memcpy(dist_graph_ptr->in_weights, sourceweights, indegree * sizeof(int));
Packit Service c5cf8c
        MPIR_Memcpy(dist_graph_ptr->out_weights, destweights, outdegree * sizeof(int));
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    mpi_errno = MPIR_Topology_put(comm_dist_graph_ptr, topo_ptr);
Packit Service c5cf8c
    if (mpi_errno)
Packit Service c5cf8c
        MPIR_ERR_POP(mpi_errno);
Packit Service c5cf8c
Packit Service c5cf8c
    MPIR_OBJ_PUBLISH_HANDLE(*comm_dist_graph, comm_dist_graph_ptr->handle);
Packit Service c5cf8c
    MPIR_CHKPMEM_COMMIT();
Packit Service c5cf8c
    /* ... end of body of routine ... */
Packit Service c5cf8c
  fn_exit:
Packit Service c5cf8c
    MPIR_FUNC_TERSE_EXIT(MPID_STATE_MPI_DIST_GRAPH_CREATE_ADJACENT);
Packit Service c5cf8c
    MPID_THREAD_CS_EXIT(GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX);
Packit Service c5cf8c
    return mpi_errno;
Packit Service c5cf8c
Packit Service c5cf8c
    /* --BEGIN ERROR HANDLING-- */
Packit Service c5cf8c
  fn_fail:
Packit Service c5cf8c
    MPIR_CHKPMEM_REAP();
Packit Service c5cf8c
#ifdef HAVE_ERROR_CHECKING
Packit Service c5cf8c
    mpi_errno =
Packit Service c5cf8c
        MPIR_Err_create_code(mpi_errno, MPIR_ERR_RECOVERABLE, FCNAME, __LINE__, MPI_ERR_OTHER,
Packit Service c5cf8c
                             "**mpi_dist_graph_create_adjacent",
Packit Service c5cf8c
                             "**mpi_dist_graph_create_adjacent %C %d %p %p %d %p %p %I %d %p",
Packit Service c5cf8c
                             comm_old, indegree, sources, sourceweights, outdegree, destinations,
Packit Service c5cf8c
                             destweights, info, reorder, comm_dist_graph);
Packit Service c5cf8c
#endif
Packit Service c5cf8c
    mpi_errno = MPIR_Err_return_comm(comm_ptr, FCNAME, mpi_errno);
Packit Service c5cf8c
    goto fn_exit;
Packit Service c5cf8c
    /* --END ERROR HANDLING-- */
Packit Service c5cf8c
}