This source file includes following definitions.
- MPI_Comm_spawn
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 #include "ompi_config.h"
27 #include <stdio.h>
28
29 #include "opal/util/show_help.h"
30
31 #include "ompi/info/info.h"
32 #include "ompi/mpi/c/bindings.h"
33 #include "ompi/runtime/params.h"
34 #include "ompi/runtime/mpiruntime.h"
35 #include "ompi/communicator/communicator.h"
36 #include "ompi/errhandler/errhandler.h"
37 #include "ompi/dpm/dpm.h"
38 #include "ompi/memchecker.h"
39
40 #if OMPI_BUILD_MPI_PROFILING
41 #if OPAL_HAVE_WEAK_SYMBOLS
42 #pragma weak MPI_Comm_spawn = PMPI_Comm_spawn
43 #endif
44 #define MPI_Comm_spawn PMPI_Comm_spawn
45 #endif
46
47 static const char FUNC_NAME[] = "MPI_Comm_spawn";
48
49
50 int MPI_Comm_spawn(const char *command, char *argv[], int maxprocs, MPI_Info info,
51 int root, MPI_Comm comm, MPI_Comm *intercomm,
52 int array_of_errcodes[])
53 {
54 int rank, rc=OMPI_SUCCESS, i, flag;
55 bool send_first = false;
56 ompi_communicator_t *newcomp=NULL;
57 char port_name[MPI_MAX_PORT_NAME];
58 bool non_mpi = false;
59
60 MEMCHECKER(
61 memchecker_comm(comm);
62 );
63
64 if ( MPI_PARAM_CHECK ) {
65 OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
66
67 if ( ompi_comm_invalid (comm)) {
68 return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_COMM,
69 FUNC_NAME);
70 }
71 if ( OMPI_COMM_IS_INTER(comm)) {
72 return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_COMM,
73 FUNC_NAME);
74 }
75 if ( (0 > root) || (ompi_comm_size(comm) <= root) ) {
76 return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ARG,
77 FUNC_NAME);
78 }
79 if ( NULL == intercomm ) {
80 return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ARG,
81 FUNC_NAME);
82 }
83 }
84
85 rank = ompi_comm_rank ( comm );
86 if ( MPI_PARAM_CHECK ) {
87 if ( rank == root ) {
88 if ( NULL == command ) {
89 return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ARG,
90 FUNC_NAME);
91 }
92 if ( 0 > maxprocs ) {
93 return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ARG,
94 FUNC_NAME);
95 }
96 if (NULL == info || ompi_info_is_freed(info)) {
97 return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_INFO,
98 FUNC_NAME);
99 }
100 }
101 }
102
103 if (!ompi_mpi_dynamics_is_enabled(FUNC_NAME)) {
104 return OMPI_ERRHANDLER_INVOKE(comm, OMPI_ERR_NOT_SUPPORTED, FUNC_NAME);
105 }
106
107
108 memset(port_name, 0, MPI_MAX_PORT_NAME);
109
110
111 if (rank == root) {
112 ompi_info_get_bool(info, "ompi_non_mpi", &non_mpi, &flag);
113 }
114
115 OPAL_CR_ENTER_LIBRARY();
116
117 if ( rank == root ) {
118 if (!non_mpi) {
119
120
121 if (OMPI_SUCCESS != (rc = ompi_dpm_open_port (port_name))) {
122 goto error;
123 }
124 } else if (1 < ompi_comm_size(comm)) {
125
126 rc = OMPI_ERR_NOT_SUPPORTED;
127 goto error;
128 }
129 if (OMPI_SUCCESS != (rc = ompi_dpm_spawn (1, &command, &argv, &maxprocs,
130 &info, port_name))) {
131 goto error;
132 }
133 }
134
135 if (non_mpi) {
136 newcomp = MPI_COMM_NULL;
137 } else {
138 rc = ompi_dpm_connect_accept (comm, root, port_name, send_first, &newcomp);
139 }
140
141 error:
142 if (OPAL_ERR_NOT_SUPPORTED == rc) {
143 opal_show_help("help-mpi-api.txt",
144 "MPI function not supported",
145 true,
146 FUNC_NAME,
147 "Underlying runtime environment does not support spawn functionality");
148 }
149
150
151 if (rank == root && !non_mpi) {
152 ompi_dpm_close_port(port_name);
153 }
154
155 OPAL_CR_EXIT_LIBRARY();
156
157
158 if (MPI_ERRCODES_IGNORE != array_of_errcodes) {
159 for ( i=0; i < maxprocs; i++ ) {
160 array_of_errcodes[i]=rc;
161 }
162 }
163
164 *intercomm = newcomp;
165 OMPI_ERRHANDLER_RETURN (rc, comm, rc, FUNC_NAME);
166 }