From ea94dbb62678ee94cf85a9a3dfe2310e695528b2 Mon Sep 17 00:00:00 2001 From: Yohai Meiron Date: Thu, 2 Apr 2020 21:49:52 -0400 Subject: [PATCH] Moved the active search outside of the main loop --- phigrape.cpp | 153 +++++++++++++++++++++++++++------------------------ 1 file changed, 81 insertions(+), 72 deletions(-) diff --git a/phigrape.cpp b/phigrape.cpp index 4ffe33f..0e61467 100644 --- a/phigrape.cpp +++ b/phigrape.cpp @@ -529,6 +529,60 @@ void energy_contr(const double time_cur, const double timesteps, const double n_ E_tot_corr_sd_0 = 0; } +class Active_search { + // TODO you can add pointers to t and dt at the constructor, no point giving them at get_minimum_time but without the size. +public: + Active_search(const int myRank, const int n_proc, const int n_loc, const int N) + : myRank(myRank), n_proc(n_proc), n_loc(n_loc), N(N) + { + ind_act_loc = new int[n_loc]; + } + ~Active_search() { delete[] ind_act_loc; }; + double get_minimum_time(const double t[], const double dt[]) + { + double min_t_loc, min_t; +#ifdef ACT_DEF_GRAPITE + min_t_loc = grapite_get_minimum_time(); +#else + min_t_loc = t[myRank*n_loc]+dt[myRank*n_loc]; + for (int j=myRank*n_loc+1; j<(myRank+1)*n_loc; j++) { + double tmp = t[j] + dt[j]; + if (tmp < min_t_loc) min_t_loc = tmp; + } +#endif + /* Reduce the "global" min_t from min_t_loc "local" on all processors) */ + MPI_Allreduce(&min_t_loc, &min_t, 1, MPI_DOUBLE, MPI_MIN, MPI_COMM_WORLD); + return min_t; + } + void get_active_indices(const double min_t, const double t[], const double dt[], int ind_act[], int *n_act) + { +#ifdef ACT_DEF_GRAPITE + int n_act_loc; + grapite_active_search(min_t, ind_act_loc, &n_act_loc); + if (myRank > 0) + for (int i=0; i 0) - for (int i=0; i