This source file includes following definitions.
- MPI_Intercomm_merge
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 #include "ompi_config.h"
28 #include <string.h>
29
30 #include "ompi/mpi/c/bindings.h"
31 #include "ompi/runtime/params.h"
32 #include "ompi/errhandler/errhandler.h"
33 #include "ompi/communicator/communicator.h"
34 #include "ompi/proc/proc.h"
35 #include "ompi/memchecker.h"
36
37 #if OMPI_BUILD_MPI_PROFILING
38 #if OPAL_HAVE_WEAK_SYMBOLS
39 #pragma weak MPI_Intercomm_merge = PMPI_Intercomm_merge
40 #endif
41 #define MPI_Intercomm_merge PMPI_Intercomm_merge
42 #endif
43
44 static const char FUNC_NAME[] = "MPI_Intercomm_merge";
45
46
47 int MPI_Intercomm_merge(MPI_Comm intercomm, int high,
48 MPI_Comm *newcomm)
49 {
50 ompi_communicator_t *newcomp=MPI_COMM_NULL;
51 ompi_proc_t **procs=NULL;
52 int local_size, remote_size;
53 int first;
54 int total_size;
55 int rc=MPI_SUCCESS;
56 int thigh = high;
57 ompi_group_t *new_group_pointer;
58
59 MEMCHECKER(
60 memchecker_comm(intercomm);
61 );
62
63 if ( MPI_PARAM_CHECK ) {
64 OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
65
66 if (ompi_comm_invalid ( intercomm ) ||
67 !( intercomm->c_flags & OMPI_COMM_INTER ) )
68 return OMPI_ERRHANDLER_INVOKE ( MPI_COMM_WORLD, MPI_ERR_COMM,
69 FUNC_NAME);
70
71 if ( NULL == newcomm )
72 return OMPI_ERRHANDLER_INVOKE ( intercomm, MPI_ERR_ARG,
73 FUNC_NAME);
74 }
75
76 OPAL_CR_ENTER_LIBRARY();
77
78 local_size = ompi_comm_size ( intercomm );
79 remote_size = ompi_comm_remote_size ( intercomm );
80 total_size = local_size + remote_size;
81 procs = (ompi_proc_t **) malloc ( total_size * sizeof(ompi_proc_t *));
82 if ( NULL == procs ) {
83 rc = MPI_ERR_INTERN;
84 goto exit;
85 }
86
87 first = ompi_comm_determine_first ( intercomm, thigh );
88 if ( MPI_UNDEFINED == first ) {
89 rc = MPI_ERR_INTERN;
90 goto exit;
91 }
92
93 if ( first ) {
94 ompi_group_union ( intercomm->c_local_group, intercomm->c_remote_group, &new_group_pointer );
95 }
96 else {
97 ompi_group_union ( intercomm->c_remote_group, intercomm->c_local_group, &new_group_pointer );
98 }
99
100 rc = ompi_comm_set ( &newcomp,
101 intercomm,
102 total_size,
103 NULL,
104 0,
105 NULL,
106 NULL,
107 intercomm->error_handler,
108 false,
109 new_group_pointer,
110 NULL
111 );
112 if ( MPI_SUCCESS != rc ) {
113 goto exit;
114 }
115
116 OBJ_RELEASE(new_group_pointer);
117 new_group_pointer = MPI_GROUP_NULL;
118
119
120 rc = ompi_comm_nextcid (newcomp, intercomm, NULL, NULL, NULL, false,
121 OMPI_COMM_CID_INTER);
122 if ( OMPI_SUCCESS != rc ) {
123 goto exit;
124 }
125
126
127 rc = ompi_comm_activate (&newcomp, intercomm, NULL, NULL, NULL, false,
128 OMPI_COMM_CID_INTER);
129 if ( OMPI_SUCCESS != rc ) {
130 goto exit;
131 }
132
133 exit:
134 OPAL_CR_EXIT_LIBRARY();
135
136 if ( NULL != procs ) {
137 free ( procs );
138 }
139 if ( MPI_SUCCESS != rc ) {
140 if ( MPI_COMM_NULL != newcomp && NULL != newcomp ) {
141 OBJ_RELEASE(newcomp);
142 }
143 *newcomm = MPI_COMM_NULL;
144 return OMPI_ERRHANDLER_INVOKE(intercomm, rc, FUNC_NAME);
145 }
146
147 *newcomm = newcomp;
148 return MPI_SUCCESS;
149 }
150