1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
2 /*
3 * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
4 * University Research and Technology
5 * Corporation. All rights reserved.
6 * Copyright (c) 2004-2013 The University of Tennessee and The University
7 * of Tennessee Research Foundation. All rights
8 * reserved.
9 * Copyright (c) 2004-2008 High Performance Computing Center Stuttgart,
10 * University of Stuttgart. All rights reserved.
11 * Copyright (c) 2004-2005 The Regents of the University of California.
12 * All rights reserved.
13 * Copyright (c) 2007-2012 Cisco Systems, Inc. All rights reserved.
14 * Copyright (c) 2012-2013 Los Alamos National Security, LLC. All rights
15 * reserved.
16 * Copyright (c) 2012-2013 Inria. All rights reserved.
17 * Copyright (c) 2015 Research Organization for Information Science
18 * and Technology (RIST). All rights reserved.
19 * $COPYRIGHT$
20 *
21 * Additional copyrights may follow
22 *
23 * $HEADER$
24 */
25 #include "ompi_config.h"
26 #include <stdio.h>
27
28 #include "ompi/mpi/c/bindings.h"
29 #include "ompi/runtime/params.h"
30 #include "ompi/communicator/communicator.h"
31 #include "ompi/errhandler/errhandler.h"
32 #include "ompi/mca/topo/base/base.h"
33 #include "ompi/memchecker.h"
34
35 #if OMPI_BUILD_MPI_PROFILING
36 #if OPAL_HAVE_WEAK_SYMBOLS
37 #pragma weak MPI_Graph_create = PMPI_Graph_create
38 #endif
39 #define MPI_Graph_create PMPI_Graph_create
40 #endif
41
42 static const char FUNC_NAME[] = "MPI_Graph_create";
43
44
45 int MPI_Graph_create(MPI_Comm old_comm, int nnodes, const int indx[],
46 const int edges[], int reorder, MPI_Comm *comm_graph)
47 {
48 mca_topo_base_module_t* topo;
49 int err;
50
51 MEMCHECKER(
52 memchecker_comm(old_comm);
53 );
54
55 /* check the arguments */
56 if (MPI_PARAM_CHECK) {
57 OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
58 if (ompi_comm_invalid(old_comm)) {
59 return OMPI_ERRHANDLER_INVOKE (MPI_COMM_WORLD, MPI_ERR_COMM,
60 FUNC_NAME);
61 } else if (OMPI_COMM_IS_INTER(old_comm)) {
62 return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_COMM,
63 FUNC_NAME);
64 }
65 if (nnodes < 0) {
66 return OMPI_ERRHANDLER_INVOKE (old_comm, MPI_ERR_ARG,
67 FUNC_NAME);
68 } else if (nnodes >= 1 && ((NULL == indx) || (NULL == edges))) {
69 return OMPI_ERRHANDLER_INVOKE (old_comm, MPI_ERR_ARG,
70 FUNC_NAME);
71 }
72
73 if (nnodes > ompi_comm_size(old_comm)) {
74 return OMPI_ERRHANDLER_INVOKE (old_comm, MPI_ERR_ARG,
75 FUNC_NAME);
76 }
77 }
78
79 /* MPI-2.1 7.5.3 states that if nnodes == 0, all processes should
80 get MPI_COMM_NULL */
81 if (0 == nnodes) {
82 *comm_graph = MPI_COMM_NULL;
83 return MPI_SUCCESS;
84 }
85 if( nnodes > old_comm->c_local_group->grp_proc_count ) {
86 return OMPI_ERRHANDLER_INVOKE (old_comm, MPI_ERR_ARG,
87 FUNC_NAME);
88 }
89
90 OPAL_CR_ENTER_LIBRARY();
91 /*
92 * everything seems to be alright with the communicator, we can go
93 * ahead and select a topology module for this purpose and create
94 * the new graph communicator
95 */
96 if (OMPI_SUCCESS != (err = mca_topo_base_comm_select(old_comm,
97 NULL,
98 &topo,
99 OMPI_COMM_GRAPH))) {
100 return err;
101 }
102
103 /* Now let that topology module rearrange procs/ranks if it wants to */
104 err = topo->topo.graph.graph_create(topo, old_comm,
105 nnodes, indx, edges,
106 (0 == reorder) ? false : true, comm_graph);
107 OPAL_CR_EXIT_LIBRARY();
108
109 if (MPI_SUCCESS != err) {
110 OBJ_RELEASE(topo);
111 return OMPI_ERRHANDLER_INVOKE(old_comm, err, FUNC_NAME);
112 }
113
114 /* All done */
115 return MPI_SUCCESS;
116 }