Skip to content

Commit

Permalink
Replace ion alltrans with global alltrans
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeshingles committed Sep 8, 2024
1 parent b7926e2 commit 9a8f4c6
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 39 deletions.
6 changes: 2 additions & 4 deletions atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,7 @@ inline auto get_includedlevels() -> int { return includedlevels; }
}

[[nodiscard]] inline auto get_downtranslist(const int element, const int ion, const int level) -> LevelTransition * {
const auto &ionref = globals::elements[element].ions[ion];
return ionref.alltransitions + ionref.levels[level].downtrans;
return globals::alltrans + globals::elements[element].ions[ion].levels[level].downtrans;
}

// the number of upward bound-bound transitions from the specified level
Expand All @@ -374,8 +373,7 @@ inline auto get_includedlevels() -> int { return includedlevels; }
}

[[nodiscard]] inline auto get_uptranslist(const int element, const int ion, const int level) -> LevelTransition * {
const auto &ionref = globals::elements[element].ions[ion];
return ionref.alltransitions + ionref.levels[level].uptrans;
return globals::alltrans + globals::elements[element].ions[ion].levels[level].uptrans;
}

[[nodiscard]] inline auto get_uptransspan(const int element, const int ion, const int level) {
Expand Down
6 changes: 3 additions & 3 deletions globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ struct LevelTransition {

struct EnergyLevel {
double epsilon{-1}; // Excitation energy of this level relative to the neutral ground level.
int uptrans{}; // Allowed upward transitions from this level
int downtrans{}; // Allowed downward transitions from this level
int nuptrans{0};
int uptrans{}; // Allowed upward transitions from this level
int ndowntrans{0};
int downtrans{}; // Allowed downward transitions from this level
PhotoionTarget *phixstargets{}; // pointer to table of target states and probabilities
int phixsstart{-1}; // index to start of photoionisation cross-sections table in global::allphixs
int nphixstargets{0}; // length of phixstargets array:
Expand All @@ -109,7 +109,6 @@ struct Ion {
int uniquelevelindexstart;
int groundcontindex;
double ionpot; // Ionisation threshold to the next ionstage
LevelTransition *alltransitions;
};

struct Element {
Expand Down Expand Up @@ -258,6 +257,7 @@ inline int opacity_case{}; // 0 grey, 1 for Fe-grp dependence.
inline std::vector<float> ion_alpha_sp; // alpha_sp for each ion and temperature table value

inline float *allphixs{};
inline LevelTransition *alltrans;

inline std::vector<Element> elements;

Expand Down
77 changes: 45 additions & 32 deletions input.cc
Original file line number Diff line number Diff line change
Expand Up @@ -477,32 +477,17 @@ void read_ion_transitions(std::fstream &ftransitiondata, const int tottransition
void add_transitions_to_unsorted_linelist(const int element, const int ion, const int nlevelsmax,
const std::vector<Transition> &transitiontable,
std::vector<int> &iondowntranstmplineindicies, int &lineindex,
std::vector<TransitionLine> &temp_linelist) {
std::vector<TransitionLine> &temp_linelist,
std::vector<LevelTransition> &temp_alltranslist) {
const int lineindex_initial = lineindex;
ptrdiff_t totupdowntrans = 0;
// pass 0 to get transition counts of each level
// pass 1 to allocate and fill transition arrays
for (int pass = 0; pass < 2; pass++) {
lineindex = lineindex_initial;
if (pass == 1) {
int alltransindex = 0;
auto &ionalltrans = globals::elements[element].ions[ion].alltransitions;

#ifdef MPI_ON
MPI_Barrier(MPI_COMM_WORLD);
MPI_Win win_alltransblock = MPI_WIN_NULL;

const auto [_, noderank_trans] = get_range_chunk(totupdowntrans, globals::node_nprocs, globals::rank_in_node);

auto size = static_cast<MPI_Aint>(noderank_trans * sizeof(LevelTransition));
int disp_unit = sizeof(LevelTransition);
MPI_Win_allocate_shared(size, disp_unit, MPI_INFO_NULL, globals::mpi_comm_node, &ionalltrans, &win_alltransblock);

MPI_Win_shared_query(win_alltransblock, 0, &size, &disp_unit, &ionalltrans);
#else
ionalltrans = static_cast<LevelTransition *>(malloc(totupdowntrans * sizeof(LevelTransition)));
#endif

int alltransindex = temp_alltranslist.size();
temp_alltranslist.resize(temp_alltranslist.size() + totupdowntrans);
for (int level = 0; level < nlevelsmax; level++) {
globals::elements[element].ions[ion].levels[level].downtrans = alltransindex;
alltransindex += get_ndowntrans(element, ion, level);
Expand Down Expand Up @@ -567,18 +552,20 @@ void add_transitions_to_unsorted_linelist(const int element, const int ion, cons
// the line list has not been sorted yet, so the store the level index for now and
// the index into the sorted line list will be set later

get_downtranslist(element, ion, level)[nupperdowntrans - 1] = {.lineindex = -1,
.targetlevelindex = lowerlevel,
.einstein_A = transition.A,
.coll_str = transition.coll_str,
.osc_strength = f_ul,
.forbidden = transition.forbidden};
get_uptranslist(element, ion, lowerlevel)[nloweruptrans - 1] = {.lineindex = -1,
.targetlevelindex = level,
.einstein_A = transition.A,
.coll_str = transition.coll_str,
.osc_strength = f_ul,
.forbidden = transition.forbidden};
temp_alltranslist[globals::elements[element].ions[ion].levels[level].downtrans + nupperdowntrans - 1] = {
.lineindex = -1,
.targetlevelindex = lowerlevel,
.einstein_A = transition.A,
.coll_str = transition.coll_str,
.osc_strength = f_ul,
.forbidden = transition.forbidden};
temp_alltranslist[globals::elements[element].ions[ion].levels[lowerlevel].uptrans + nloweruptrans - 1] = {
.lineindex = -1,
.targetlevelindex = level,
.einstein_A = transition.A,
.coll_str = transition.coll_str,
.osc_strength = f_ul,
.forbidden = transition.forbidden};
}

} else if (pass == 1 && globals::rank_in_node == 0) {
Expand Down Expand Up @@ -970,6 +957,7 @@ void read_atomicdata_files() {
globals::elements.resize(nelements_in);

std::vector<TransitionLine> temp_linelist;
std::vector<LevelTransition> temp_alltranslist;

std::vector<Transition> iontransitiontable;
std::vector<int> iondowntranstmplineindicies;
Expand Down Expand Up @@ -1143,7 +1131,7 @@ void read_atomicdata_files() {
iondowntranstmplineindicies.resize(downtranslevelstart(nlevelsmax));

add_transitions_to_unsorted_linelist(element, ion, nlevelsmax, iontransitiontable, iondowntranstmplineindicies,
lineindex, temp_linelist);
lineindex, temp_linelist, temp_alltranslist);

for (int level = 0; level < nlevelsmax; level++) {
uniquelevelindex++;
Expand Down Expand Up @@ -1204,6 +1192,31 @@ void read_atomicdata_files() {
}
}

{
// create a shared all transitions list and then copy data across, freeing the local copy
const auto totupdowntrans = totaluptrans + totaldowntrans;
assert_always(totupdowntrans == static_cast<int>(temp_alltranslist.size()));
#ifdef MPI_ON
MPI_Barrier(MPI_COMM_WORLD);
MPI_Win win_alltransblock = MPI_WIN_NULL;

const auto [_, noderank_trans] = get_range_chunk(totupdowntrans, globals::node_nprocs, globals::rank_in_node);

auto size = static_cast<MPI_Aint>(noderank_trans * sizeof(LevelTransition));
int disp_unit = sizeof(LevelTransition);
MPI_Win_allocate_shared(size, disp_unit, MPI_INFO_NULL, globals::mpi_comm_node, &globals::alltrans,
&win_alltransblock);

MPI_Win_shared_query(win_alltransblock, 0, &size, &disp_unit, &globals::alltrans);
#else
globals::alltrans = static_cast<LevelTransition *>(malloc(totupdowntrans * sizeof(LevelTransition)));
#endif
if (globals::rank_in_node == 0) {
std::copy_n(temp_alltranslist.data(), totupdowntrans, globals::alltrans);
temp_alltranslist.clear();
}
}

// create a linelist shared on node and then copy data across, freeing the local copy
TransitionLine *nonconstlinelist{};
{
Expand Down

0 comments on commit 9a8f4c6

Please sign in to comment.