(use_cases_macro_relauncher_mpi_standalone_cpp)= # Macro "**relauncherCodeFlowrateMpiStandalone.C**" ## Objective The goal of this macro is to show how to handle a code run on several threads with another memory paradigm: when the `TThreadedRun` instance is relying on shared memory (leading to possible thread-safe problem, as discussed in [](#relauncher_trun_tthreadedrun)), the MPI implementation is based on the separation of the memory. The communication is made through messages. In order to this, the usual sequential runner will be removed and another runner will be called to do the job. The `flowrate` code is provided with {{uranie}} and has been also used and discussed throughout these macros. ```{warning} This macro is different from the one discussed previously in [](#use_cases_macro_relauncher_mpi) as here, one wants to handle MPI through standalone compilation (so C++ without using the {{root}} interface) ``` ## Macro {{ "```{literalinclude} " + parent_dir + "/roottest/uranie/doc/relauncher/use_cases/cpp/relauncherCodeFlowrateMpiStandalone.C" + "\n" + ":language: cpp\n" + "```" }} Here there are few differences the most obvious one being the proper C++ structure: - there are several includes that has to be included on top the macro in order to provided the needed headers; - the main function has to follow a classical form `int main(int argc, char **argv)` which allows to modify parameters on the fly once compiled (as for the `initType` integer here through a dedicated loop). The consequence of this signature will be discussed later on; - a `usage` function has been written in order to provide interactive guidelines on how to deal with this code. Apart from this, from the variable definition to the assessor description, the structure is similar to the one discussed previously (see [](#use_cases_macro_relauncher_threaded_macro)). Once this point is reached there are two ways to construct the runner: - with the classical constructor. In this case, as one is not running a {{root}} session, the constructor will not found the interactive command parameters and the `MPI_Init` will not automatically be called, thus meaning that one needs to call this method with the proper parameters as done below: {{ "```{literalinclude} " + parent_dir + "/roottest/uranie/doc/relauncher/use_cases/cpp/relauncherCodeFlowrateMpiStandalone.C" + "\n" + ":language: cpp\n" + ":lines: 71,72\n" + "```" }} - with the new constructor provided with v4.6.0 whose argument are the usual assessor and the interactive parameters: {{ "```{literalinclude} " + parent_dir + "/roottest/uranie/doc/relauncher/use_cases/cpp/relauncherCodeFlowrateMpiStandalone.C" + "\n" + ":language: cpp\n" + ":lines: 75\n" + "```" }} The final difference is the fact that this code has to be properly compiled, using MPI-complient compilor in order to be able to produce an executable that will be run later on. This can be done like this: ```bash mpicc -o relaunStand relauncherCodeFlowrateMpiStandalone.C `echo $URANIECPPFLAG $URANIELDFLAG` -lstdc++ ``` where `mpicc` is the c++ mpi-complient compilor, the argument after `-o` is the executable name, then one can see the input file while the rest is provinding all compiling and linking flag in order to reach the goal. Finally, instead of using the classical `root -l` command, one will use this line ```bash mpirun -np N ./relaunStand initType XX ``` where the *N* part should be replaced by the number of requested threads (always strickly greater than 1) and XX should be replaced either by 0 or 1 depending on whether one wants to use the classical `TMpiRun` constructor. Once run, this macro also leads to the following plots (both initialisation are shown). ## Graph {{ "```{" "figure" "} " + parent_dir + "/roottest/build/uranie/doc/relauncher/use_cases/cpp/standalone/relauncherCodeFlowrateMpiStandalone.png\n" ":align: center\n" ":name: usecases_relauncherCodeFlowrateMpiStandalone\n" + figure_scale + "\n" "\n" "Representation of the output as a function of the first input with a colZ option when using either the classical or dedicated constructor\n" "```" }}