commit 4d335780d12d5b9bfc46835eb27e8f74be75dd30
parent 3d5c63d05a9a60597c2b06206a831bcb7b694662
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Mon, 29 Nov 2021 15:49:56 +0100
Update the API of gather_accumulators
Gather only one type of accumulator
Diffstat:
5 files changed, 59 insertions(+), 77 deletions(-)
diff --git a/src/sdis.c b/src/sdis.c
@@ -256,15 +256,14 @@ compute_process_realisations_count
res_T
gather_accumulators
(struct sdis_device* dev,
- const struct accum* per_thread_acc_temp,
- const struct accum* per_thread_acc_time,
- struct accum* acc_temp,
- struct accum* acc_time)
+ const enum mpi_sdis_message msg,
+ const struct accum* per_thread_acc,
+ struct accum* acc)
{
+ (void)msg;
ASSERT(dev);
/* Gather thread accumulators */
- sum_accums(per_thread_acc_temp, dev->nthreads, acc_temp);
- sum_accums(per_thread_acc_time, dev->nthreads, acc_time);
+ sum_accums(per_thread_acc, dev->nthreads, acc);
return RES_OK;
}
#endif
@@ -273,52 +272,38 @@ gather_accumulators
res_T
gather_accumulators
(struct sdis_device* dev,
- const struct accum* per_thread_acc_temp,
- const struct accum* per_thread_acc_time,
- struct accum* acc_temp,
- struct accum* acc_time)
+ const enum mpi_sdis_message msg,
+ const struct accum* per_thread_acc,
+ struct accum* acc)
{
- char buf[128];
- struct time t0, t1;
- struct accum* per_proc_acc_temp = NULL;
- struct accum* per_proc_acc_time = NULL;
+ struct accum* per_proc_acc = NULL;
size_t nprocs = 0;
res_T res = RES_OK;
- ASSERT(dev && per_thread_acc_temp && per_thread_acc_time);
- ASSERT(acc_temp && acc_time);
-
- time_current(&t0);
+ ASSERT(dev && per_thread_acc && acc);
if(!dev->use_mpi) {
/* Gather thread accumulators */
- sum_accums(per_thread_acc_temp, dev->nthreads, acc_temp);
- sum_accums(per_thread_acc_time, dev->nthreads, acc_time);
+ sum_accums(per_thread_acc, dev->nthreads, acc);
goto exit;
}
nprocs = (size_t)dev->mpi_nprocs;
- per_proc_acc_temp = MEM_CALLOC(dev->allocator, nprocs, sizeof(struct accum));
- per_proc_acc_time = MEM_CALLOC(dev->allocator, nprocs, sizeof(struct accum));
- if(!per_proc_acc_temp) { res = RES_MEM_ERR; goto error; }
- if(!per_proc_acc_time) { res = RES_MEM_ERR; goto error; }
+ per_proc_acc = MEM_CALLOC(dev->allocator, nprocs, sizeof(struct accum));
+ if(!per_proc_acc) { res = RES_MEM_ERR; goto error; }
/* Gather thread accumulators */
- sum_accums(per_thread_acc_temp, dev->nthreads, &per_proc_acc_temp[0]);
- sum_accums(per_thread_acc_time, dev->nthreads, &per_proc_acc_time[0]);
+ sum_accums(per_thread_acc, dev->nthreads, &per_proc_acc[0]);
/* Non master process */
if(dev->mpi_rank != 0) {
- /* Send the temperature/time accumulator to the master process */
+ /* Send the accumulator to the master process */
mutex_lock(dev->mpi_mutex);
- MPI(Send(&per_proc_acc_temp[0], sizeof(per_proc_acc_temp[0]), MPI_CHAR,
- 0/*Dst*/, MPI_SDIS_MSG_ACCUM_TEMP, MPI_COMM_WORLD));
- MPI(Send(&per_proc_acc_time[0], sizeof(per_proc_acc_time[0]), MPI_CHAR,
- 0/*Dst*/, MPI_SDIS_MSG_ACCUM_TIME, MPI_COMM_WORLD));
+ MPI(Send(&per_proc_acc[0], sizeof(per_proc_acc[0]), MPI_CHAR, 0/*Dst*/,
+ msg, MPI_COMM_WORLD));
mutex_unlock(dev->mpi_mutex);
- *acc_temp = per_proc_acc_temp[0];
- *acc_time = per_proc_acc_time[0];
+ *acc = per_proc_acc[0];
/* Master process */
} else {
@@ -328,34 +313,20 @@ gather_accumulators
FOR_EACH(iproc, 1, dev->mpi_nprocs) {
MPI_Request req;
- /* Asynchronously receive the temperature accumulator of `iproc' */
- mutex_lock(dev->mpi_mutex);
- MPI(Irecv(&per_proc_acc_temp[iproc], sizeof(per_proc_acc_temp[iproc]),
- MPI_CHAR, iproc, MPI_SDIS_MSG_ACCUM_TEMP, MPI_COMM_WORLD, &req));
- mutex_unlock(dev->mpi_mutex);
- mpi_waiting_for_request(dev, &req);
-
- /* Asynchronously receive the time accumulator of `iproc' */
+ /* Asynchronously receive the accumulator of `iproc' */
mutex_lock(dev->mpi_mutex);
- MPI(Irecv(&per_proc_acc_time[iproc], sizeof(per_proc_acc_time[iproc]),
- MPI_CHAR, iproc, MPI_SDIS_MSG_ACCUM_TIME, MPI_COMM_WORLD, &req));
+ MPI(Irecv(&per_proc_acc[iproc], sizeof(per_proc_acc[iproc]), MPI_CHAR,
+ iproc, msg, MPI_COMM_WORLD, &req));
mutex_unlock(dev->mpi_mutex);
mpi_waiting_for_request(dev, &req);
}
/* Sum the process accumulators */
- sum_accums(per_proc_acc_temp, (size_t)dev->mpi_nprocs, acc_temp);
- sum_accums(per_proc_acc_time, (size_t)dev->mpi_nprocs, acc_time);
+ sum_accums(per_proc_acc, (size_t)dev->mpi_nprocs, acc);
}
exit:
- if(res == RES_OK) {
- time_sub(&t0, time_current(&t1), &t0);
- time_dump(&t0, TIME_ALL, NULL, buf, sizeof(buf));
- log_info(dev, "Accumulators gathered in %s.\n", buf);
- }
- if(per_proc_acc_temp) MEM_RM(dev->allocator, per_proc_acc_temp);
- if(per_proc_acc_time) MEM_RM(dev->allocator, per_proc_acc_time);
+ if(per_proc_acc) MEM_RM(dev->allocator, per_proc_acc);
return res;
error:
goto exit;
diff --git a/src/sdis_c.h b/src/sdis_c.h
@@ -18,9 +18,20 @@
#include <rsys/rsys.h>
+/* Id of the messages sent between processes */
+enum mpi_sdis_message {
+ MPI_SDIS_MSG_PROGRESS, /* Progress status */
+ MPI_SDIS_MSG_ACCUM_TEMP, /* Temperature accumulator */
+ MPI_SDIS_MSG_ACCUM_TIME, /* Time accumulator */
+ MPI_SDIS_MSG_COUNT__
+};
+
/* Forward declarations */
struct accum;
struct sdis_device;
+struct sdis_estimator;
+struct sdis_green_function;
+struct sdis_scene;
struct ssp_rng;
struct ssp_rng_proxy;
@@ -67,25 +78,23 @@ compute_process_realisations_count
(const struct sdis_device* dev,
const size_t overall_realisations_count);
-/* Gather the accumulators and sum them in acc_<temp|time>. With MPI, non
- * master processes store in acc_<temp|time> the gathering of their per thread
- * accumulators that are sent to the master process. The master process gathers
- * their per thread accumulators and the per process ones and save the result
- * in acc_<temp|time> */
+/* Gather the accumulators and sum them in acc. With MPI, non master processes
+ * store in acc the gathering of their per thread accumulators that are sent to
+ * the master process. The master process gathers the per thread accumulators
+ * and the per process ones and save the result in acc */
extern LOCAL_SYM res_T
gather_accumulators
(struct sdis_device* dev,
- const struct accum* per_thread_acc_temp,
- const struct accum* per_thread_acc_time,
- struct accum* acc_temp,
- struct accum* acc_time);
+ const enum mpi_sdis_message msg,
+ const struct accum* per_thread_acc,
+ struct accum* acc);
extern LOCAL_SYM res_T
setup_estimator
(struct sdis_estimator* estimator,
const struct ssp_rng_proxy* proxy,
- const struct accum* per_thread_acc_temp,
- const struct accum* per_thread_acc_time,
+ const struct accum* acc_temp,
+ const struct accum* acc_time,
const size_t overall_realisations_count);
extern LOCAL_SYM res_T
diff --git a/src/sdis_mpi.c b/src/sdis_mpi.c
@@ -13,6 +13,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
+#include "sdis_c.h"
#include "sdis_device_c.h"
#include "sdis_mpi.h"
diff --git a/src/sdis_mpi.h b/src/sdis_mpi.h
@@ -23,14 +23,6 @@
#include <rsys/rsys.h>
#include <mpi.h>
-/* Id of the messages sent between processes */
-enum mpi_sdis_message {
- MPI_SDIS_MSG_PROGRESS, /* Progress status */
- MPI_SDIS_MSG_ACCUM_TEMP, /* Temperature accumulator */
- MPI_SDIS_MSG_ACCUM_TIME, /* Time accumulator */
- MPI_SDIS_MSG_COUNT__
-};
-
/* Forward declarations */
struct sdis_device;
diff --git a/src/sdis_solve_probe_Xd.h b/src/sdis_solve_probe_Xd.h
@@ -74,7 +74,7 @@ XD(solve_probe)
struct sdis_estimator** out_estimator) /* May be NULL <=> No estimator */
{
/* Time registration */
- struct time solve_t0, solve_t1;
+ struct time time0, time1;
char buf[128]; /* Temporary buffer used to store formated time */
/* Device variables */
@@ -171,7 +171,7 @@ XD(solve_probe)
print_progress(scn->dev, progress, "Solving probe temperature: ");
/* Begin time registration of the computation */
- time_current(&solve_t0);
+ time_current(&time0);
/* Here we go! Launch the Monte Carlo estimation */
nrealisations = compute_process_realisations_count(scn->dev, args->nrealisations);
@@ -285,17 +285,26 @@ XD(solve_probe)
log_info(scn->dev, "\n");
/* Report computation time */
- time_sub(&solve_t0, time_current(&solve_t1), &solve_t0);
- time_dump(&solve_t0, TIME_ALL, NULL, buf, sizeof(buf));
+ time_sub(&time0, time_current(&time1), &time0);
+ time_dump(&time0, TIME_ALL, NULL, buf, sizeof(buf));
log_info(scn->dev, "Probe temperature solved in %s.\n", buf);
/* Setup the estimated values */
if(out_estimator) {
struct accum acc_temp, acc_time;
+ time_current(&time0);
+
+ res = gather_accumulators
+ (scn->dev, MPI_SDIS_MSG_ACCUM_TEMP, per_thread_acc_temp, &acc_temp);
+ if(res != RES_OK) goto error;
res = gather_accumulators
- (scn->dev, per_thread_acc_temp, per_thread_acc_time, &acc_temp, &acc_time);
- if(res != RES_OK) goto exit;
+ (scn->dev, MPI_SDIS_MSG_ACCUM_TIME, per_thread_acc_time, &acc_time);
+ if(res != RES_OK) goto error;
+
+ time_sub(&time0, time_current(&time1), &time0);
+ time_dump(&time0, TIME_ALL, NULL, buf, sizeof(buf));
+ log_info(scn->dev, "Accumulators gathered in %s.\n", buf);
if(is_master_process) {
res = setup_estimator