1313// information, see the LICENSE file in the top level directory of the
1414// distribution.
1515
16-
1716#include < sst_config.h>
18-
1917#include " pin3frontend.h"
2018
19+ #ifdef SST_CONFIG_HAVE_MPI
20+ // TODO?
21+ #endif
22+
2123#include < signal.h>
2224#if !defined(SST_COMPILE_MACOSX)
2325#include < sys/prctl.h>
3032#include < fcntl.h>
3133#include < stdio.h>
3234#include < fcntl.h>
33-
3435#include < time.h>
35-
3636#include < string.h>
3737
3838#define ARIEL_INNER_STRINGIZE (input ) #input
@@ -111,7 +111,13 @@ Pin3Frontend::Pin3Frontend(ComponentId_t id, Params& params, uint32_t cores, uin
111111 output->verbose (CALL_INFO, 1 , 0 , " Base pipe name: %s\n " , shmem_region_name.c_str ());
112112
113113 // MPI Launcher options
114- mpimode = params.find <int >(" mpimode" , 0 );
114+ // mpimode = params.find<int>("mpimode", 0);
115+ #ifdef USE_MPI
116+ mpimode = 1 ;
117+ #else
118+ mpimode = 0 ;
119+ #endif
120+
115121 if (mpimode) {
116122 mpilauncher = params.find <std::string>(" mpilauncher" , ARIEL_STRINGIZE (MPILAUNCHER_EXECUTABLE));
117123 mpiranks = params.find <int >(" mpiranks" , 1 );
@@ -322,10 +328,16 @@ void Pin3Frontend::init(unsigned int phase)
322328 // Init the child_pid = 0, this prevents problems in emergencyShutdown()
323329 // if forkPINChild() calls fatal (i.e. the child_pid would not be set)
324330 child_pid = 0 ;
325- if (mpimode == 1 ) {
331+ if (mpimode == 0 ) { // TODO CHANGE BACK
326332 // Ariel will fork the MPI launcher which will itself fork pin
327- child_pid = forkPINChild (mpilauncher.c_str (), execute_args, execute_env, redirect_info);
333+ printf (" --------------------\n " );
334+ printf (" --- MPI PIN ---\n " );
335+ printf (" --------------------\n " );
336+ child_pid = forkPINChildMPI (mpilauncher.c_str (), execute_args, execute_env, redirect_info);
328337 } else {
338+ printf (" --------------------\n " );
339+ printf (" --- Regular PIN ---\n " );
340+ printf (" --------------------\n " );
329341 child_pid = forkPINChild (appLauncher.c_str (), execute_args, execute_env, redirect_info);
330342 }
331343 output->verbose (CALL_INFO, 1 , 0 , " Returned from launching PIN. Waiting for child to attach.\n " );
@@ -348,6 +360,59 @@ ArielTunnel* Pin3Frontend::getTunnel() {
348360 return tunnel;
349361}
350362
363+ int Pin3Frontend::forkPINChildMPI (const char * app, char ** args, std::map<std::string, std::string>& app_env, redirect_info_t redirect_info) {
364+ #ifdef USE_MPI
365+ if (isSimulationRunModeInit ())
366+ return 0 ;
367+ #endif
368+
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 (" app %d - %s\n " , i, args[1 ]);
389+ }
390+
391+ int count = 1 ;
392+ char *array_of_commands[] = {args[0 ]};
393+ char *argv[] = {" 20" , NULL };
394+ char **array_of_argv[] = {args+1 };
395+ int array_of_maxprocs[] = {1 };
396+
397+ /* Working for 1 rank
398+ int count = 1;
399+ char *array_of_commands[] = {args[0]};
400+ char *argv[] = {"20", NULL};
401+ char **array_of_argv[] = {args+1};
402+ int array_of_maxprocs[] = {1};
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+
410+ // TODO: Check ret and exit is non-zero
411+ free (app2);
412+
413+ return 1 ;
414+ }
415+
351416int Pin3Frontend::forkPINChild (const char * app, char ** args, std::map<std::string, std::string>& app_env, redirect_info_t redirect_info) {
352417 // If user only wants to init the simulation then we do NOT fork the binary
353418 if (isSimulationRunModeInit ())
0 commit comments