Skip to content

Commit

Permalink
Switch uptrans and downtrans from pointers to indices
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeshingles committed Sep 8, 2024
1 parent e606320 commit fafbb9b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 42 deletions.
8 changes: 4 additions & 4 deletions atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,8 @@ inline auto get_includedlevels() -> int { return includedlevels; }
return globals::elements[element].ions[ion].levels[level].ndowntrans;
}

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

// the number of upward bound-bound transitions from the specified level
Expand All @@ -372,8 +372,8 @@ inline auto get_includedlevels() -> int { return includedlevels; }
return globals::elements[element].ions[ion].levels[level].nuptrans;
}

[[nodiscard]] inline auto get_uptranslist(const int element, const int ion, const int level) {
return globals::elements[element].ions[ion].levels[level].uptrans;
[[nodiscard]] inline auto get_uptranslist(const int element, const int ion, const int level) -> LevelTransition * {
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
8 changes: 4 additions & 4 deletions globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ struct LevelTransition {
};

struct EnergyLevel {
double epsilon{-1}; // Excitation energy of this level relative to the neutral ground level.
LevelTransition *uptrans{}; // Allowed upward transitions from this level
LevelTransition *downtrans{}; // Allowed downward transitions from this level
double epsilon{-1}; // Excitation energy of this level relative to the neutral ground 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
81 changes: 47 additions & 34 deletions input.cc
Original file line number Diff line number Diff line change
Expand Up @@ -477,37 +477,22 @@ 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 = &ionalltrans[alltransindex];
globals::elements[element].ions[ion].levels[level].downtrans = alltransindex;
alltransindex += get_ndowntrans(element, ion, level);

globals::elements[element].ions[ion].levels[level].uptrans = &ionalltrans[alltransindex];
globals::elements[element].ions[ion].levels[level].uptrans = alltransindex;
alltransindex += get_nuptrans(element, ion, level);

set_ndowntrans(element, ion, level, 0);
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 fafbb9b

Please sign in to comment.