stardis-test

Test Stardis behaviors
git clone git://git.meso-star.fr/stardis-test.git
Log | Files | Refs | README | LICENSE

commit 7238d80ee87fcf12b2ab7ea95bee058c9811d24a
parent e03b02486597aabc4ffaa48edeffca7182fcbd5e
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Mon, 26 Feb 2024 15:14:28 +0100

Use MPI to parallelize the calculation of boundary probes

Check whether Stardis is compiled with MPI support and, if so, run it
with mpirun to calculate the temperature for a list of boundary probes.
In fact, the calculation could be less efficient with MPI than without,
since mpirun is run with naive arguments that don't take the host
architecture into account.

Diffstat:
Msrc/sadist_probe_boundary.c | 35++++++++++++++++++++++++++++++++---
1 file changed, 32 insertions(+), 3 deletions(-)

diff --git a/src/sadist_probe_boundary.c b/src/sadist_probe_boundary.c @@ -86,6 +86,7 @@ static const struct args ARGS_DEFAULT = ARGS_DEFAULT__; /* Commands to calculate 1 or N probes */ #define COMMAND1 "stardis -V3 -P "STR(PX)","STR(PY)","STR(PZ)" -M "FILENAME_SCENE #define COMMANDN "stardis -V3 -L "FILENAME_PROBES" -M "FILENAME_SCENE +#define COMMANDN_MPI "mpirun -n 2 "COMMANDN /******************************************************************************* * Helper functions @@ -96,6 +97,28 @@ rand_canonic(void) return (double)rand() / (double)((long)RAND_MAX - 1); } +static int +is_mpi_enabled(void) +{ + char buf[128] = {0}; + FILE* sdis = NULL; + FILE* grep = NULL; + + if(!(sdis = popen("stardis -v", "r"))) + perror("stardis"), exit(errno); + + if(!(grep = popen("grep -qe \" MPI is enabled\"", "w"))) + perror("grep"), exit(errno); + + while(fgets(buf, sizeof(buf), sdis) && !feof(sdis)) { + if(fputs(buf, grep) == EOF) abort(); + } + + if(ferror(sdis)) errno=EIO, perror("stardis"), exit(errno); + if(pclose(sdis) == -1) perror("stardis"), exit(errno); + return !pclose(grep); +} + static void sample_unit_sphere(double p[3]) { @@ -354,6 +377,7 @@ error: static int runN(const struct sadist_trilinear_profile* profile, const size_t nprobes) { + const char* command = NULL; double* probes = NULL; /* Positions */ double* results = NULL; /* Expected values and standard deviations */ FILE* output = NULL; @@ -375,11 +399,16 @@ runN(const struct sadist_trilinear_profile* profile, const size_t nprobes) if((err = init_probe_list(probes, nprobes))) goto error; - printf(COMMANDN"\n"); + if(is_mpi_enabled()) { + command = COMMANDN_MPI; + } else { + command = COMMANDN; + } + printf("%s\n", command); - if(!(output = popen(COMMANDN, "r"))) { + if(!(output = popen(command, "r"))) { fprintf(stderr, "Error executing stardis -- %s\n", strerror(errno)); - fprintf(stderr, "\t"COMMAND1"\n"); + fprintf(stderr, "\t%s\n", command); err = errno; goto error; }