3434#include < fcntl.h>
3535#include < time.h>
3636#include < string.h>
37+ #include < sstream>
3738
3839#define ARIEL_INNER_STRINGIZE (input ) #input
3940#define ARIEL_STRINGIZE (input ) ARIEL_INNER_STRINGIZE(input)
@@ -111,24 +112,12 @@ Pin3Frontend::Pin3Frontend(ComponentId_t id, Params& params, uint32_t cores, uin
111112 output->verbose (CALL_INFO, 1 , 0 , " Base pipe name: %s\n " , shmem_region_name.c_str ());
112113
113114 // MPI Launcher options
114- // mpimode = params.find<int>("mpimode", 0);
115- #ifdef USE_MPI
116- mpimode = 1 ;
117- #else
118- mpimode = 0 ;
119- #endif
120-
121- // if (mpimode) { //TODO put this back
122- mpilauncher = params.find <std::string>(" mpilauncher" , ARIEL_STRINGIZE (MPILAUNCHER_EXECUTABLE));
123- mpiranks = params.find <int >(" mpiranks" , 1 );
124- mpitracerank = params.find <int >(" mpitracerank" , 0 );
125- // }
115+ mpimode = params.find <int >(" mpimode" , 0 );
126116
127117 // MPI Launcher error checking
128118 if (mpimode == 1 ) {
129- if (mpilauncher.compare (" " ) == 0 ) {
130- output->fatal (CALL_INFO, -1 , " mpimode=1 was specified but parameter `mpilauncher` is an empty string" );
131- }
119+ mpiranks = params.find <int >(" mpiranks" , 1 );
120+ mpitracerank = params.find <int >(" mpitracerank" , 0 );
132121
133122 if (redirect_info.stdin_file .compare (" " ) != 0 || redirect_info.stdout_file .compare (" " ) != 0 || redirect_info.stderr_file .compare (" " ) != 0 ) {
134123 output->fatal (CALL_INFO, -1 , " Using an MPI launcher and redirected I/O is not supported.\n " );
@@ -142,52 +131,18 @@ Pin3Frontend::Pin3Frontend(ComponentId_t id, Params& params, uint32_t cores, uin
142131 output->fatal (CALL_INFO, -1 , " The value of `mpitracerank` must be in [0,mpiranks) Got %d.\n " , mpitracerank);
143132 }
144133
145- }
146-
147- if (mpimode == 1 ) {
148- output->verbose (CALL_INFO, 1 , 0 , " Ariel-MPI: MPI launcher: %s\n " , mpilauncher.c_str ());
149134 output->verbose (CALL_INFO, 1 , 0 , " Ariel-MPI: MPI ranks: %d\n " , mpiranks);
150135 output->verbose (CALL_INFO, 1 , 0 , " Ariel-MPI: MPI trace rank: %d\n " , mpitracerank);
151136 }
152137
153-
154138 appLauncher = params.find <std::string>(" launcher" , PINTOOL_EXECUTABLE);
155139
156140 const uint32_t launch_param_count = (uint32_t ) params.find <uint32_t >(" launchparamcount" , 0 );
157141 const uint32_t pin_arg_count = 37 + launch_param_count;
158142
159- uint32_t mpi_args = 0 ;
160- if (mpimode == 1 ) {
161- // We need one argument for the launcher, one for the number of ranks,
162- // and one for the rank to trace
163- mpi_args = 3 ;
164- }
165-
166- execute_args = (char **) malloc (sizeof (char *) * (mpi_args + pin_arg_count + app_argc));
143+ execute_args = (char **) malloc (sizeof (char *) * (pin_arg_count + app_argc));
167144 uint32_t arg = 0 ; // Track current arg
168145
169- if (mpimode == 1 ) {
170- // Prepend mpilauncher to execute_args
171- output->verbose (CALL_INFO, 1 , 0 , " Processing mpilauncher arguments...\n " );
172- std::string mpiranks_str = std::to_string (mpiranks);
173- std::string mpitracerank_str = std::to_string (mpitracerank);
174-
175- size_t mpilauncher_size = sizeof (char ) * (mpilauncher.size () + 2 );
176- execute_args[arg] = (char *) malloc (mpilauncher_size);
177- snprintf (execute_args[arg], mpilauncher_size, " %s" , mpilauncher.c_str ());
178- arg++;
179-
180- size_t mpiranks_str_size = sizeof (char ) * (mpiranks_str.size () + 2 );
181- execute_args[arg] = (char *) malloc (mpiranks_str_size);
182- snprintf (execute_args[arg], mpiranks_str_size, " %s" , mpiranks_str.c_str ());
183- arg++;
184-
185- size_t mpitracerank_str_size = sizeof (char ) * (mpitracerank_str.size () + 2 );
186- execute_args[arg] = (char *) malloc (mpitracerank_str_size);
187- snprintf (execute_args[arg], mpitracerank_str_size, " %s" , mpitracerank_str.c_str ());
188- arg++;
189- }
190-
191146 const uint32_t profileFunctions = (uint32_t ) params.find <uint32_t >(" profilefunctions" , 0 );
192147
193148 output->verbose (CALL_INFO, 1 , 0 , " Processing application arguments...\n " );
@@ -197,13 +152,6 @@ Pin3Frontend::Pin3Frontend(ComponentId_t id, Params& params, uint32_t cores, uin
197152 snprintf (execute_args[arg], execute_args_size, " %s" , appLauncher.c_str ());
198153 arg++;
199154
200-
201-
202- #if 0
203- execute_args[arg++] = const_cast<char*>("-pause_tool");
204- execute_args[arg++] = const_cast<char*>("15");
205- #endif
206-
207155 execute_args[arg++] = const_cast <char *>(" -follow_execv" );
208156
209157 size_t param_name_buffer_size = sizeof (char ) * 512 ;
@@ -328,8 +276,7 @@ void Pin3Frontend::init(unsigned int phase)
328276 // Init the child_pid = 0, this prevents problems in emergencyShutdown()
329277 // if forkPINChild() calls fatal (i.e. the child_pid would not be set)
330278 child_pid = 0 ;
331- if (mpimode == 0 ) { // TODO CHANGE BACK
332- // Ariel will fork the MPI launcher which will itself fork pin
279+ if (mpimode == 1 ) {
333280 printf (" --------------------\n " );
334281 printf (" --- MPI PIN ---\n " );
335282 printf (" --------------------\n " );
@@ -366,57 +313,22 @@ int Pin3Frontend::forkPINChildMPI(const char* app, char** args, std::map<std::st
366313 return 0 ;
367314#endif
368315
369- // Convert app to non-const
370-
371- char *app2 = (char *)malloc (std::strlen (app) + 1 );
372- if (!app2) return 0 ; // TODO proper error condition
373- std::strcpy (app2, app);
374-
375- // Find where the PIN arguments end
376- int app_idx = -1 ;
377- for (int i = 0 ; args[i] != NULL ; i++) {
378- if (strcmp (args[i], " --" ) == 0 ) {
379- app_idx = i+1 ;
380- break ;
381- }
382- }
383- if (app_idx == -1 ) {
384- // TODO: Error not found
385- }
386-
387- for (int i = app_idx; args[i] != NULL ; i++) {
388- printf (" apparg %d - %s\n " , i, args[i]);
316+ // NOTE: Env var stuff is not yet implemented in the core
317+ std::ostringstream envstring;
318+ for (const auto & entry : app_env) {
319+ envstring << entry.first << " =" << entry.second << " \n " ;
389320 }
390321
391- int count = 2 ;
392- char *array_of_commands[] = {args[0 ], args[app_idx]};
393- char **array_of_argv[] = {args+1 , args+app_idx+1 };
394- int array_of_maxprocs[] = {1 ,1 };
395-
396- /* Working for 1 rank
397- int count = 1;
398- char *array_of_commands[] = {args[0]};
399- char *argv[] = {"20", NULL};
400- char **array_of_argv[] = {args+1};
401- int array_of_maxprocs[] = {1};
402- */
403-
404- /*
405- int ret = SST::Core::Interprocess::SST_MPI_Comm_spawn_multiple(count,
406- array_of_commands,
407- array_of_argv,
408- array_of_maxprocs,
409- tracerank);
410- */
411- printf (" [SST ELEMENTS] ranks: %d, tracerank: %d\n " , mpiranks, mpitracerank);
412322 int ret = SST::Core::Interprocess::SST_MPI_Comm_spawn_multiple (
413323 args,
414324 mpiranks,
415- mpitracerank
325+ mpitracerank,
326+ envstring.str ().c_str ()
416327 );
417328
418- // TODO: Check ret and exit is non-zero
419- free (app2);
329+ if (ret) {
330+ output->fatal (CALL_INFO, 1 , 0 , " Non-zero return from SST_MPI_Comm_spawn_multiple\n " );
331+ }
420332
421333 return 1 ;
422334}
0 commit comments