|
| 1 | +#include <iostream> |
| 2 | +#include <vector> |
| 3 | + |
| 4 | +#include "coreneuron/coreneuron.hpp" |
| 5 | +#include "coreneuron/mpi/nrnmpi.h" |
| 6 | +#include "coreneuron/mpi/nrnmpi_impl.h" |
| 7 | + |
| 8 | +namespace coreneuron { |
| 9 | + |
| 10 | +/** display global mechanism count */ |
| 11 | +void write_mech_report() { |
| 12 | + /// mechanim count across all gids, local to rank |
| 13 | + const auto n_memb_func = corenrn.get_memb_funcs().size(); |
| 14 | + std::vector<unsigned long long> local_mech_count(n_memb_func, 0); |
| 15 | + |
| 16 | + /// each gid record goes on separate row, only check non-empty threads |
| 17 | + for (size_t i = 0; i < nrn_nthread; i++) { |
| 18 | + const auto& nt = nrn_threads[i]; |
| 19 | + for (auto* tml = nt.tml; tml; tml = tml->next) { |
| 20 | + const int type = tml->index; |
| 21 | + const auto& ml = tml->ml; |
| 22 | + local_mech_count[type] += ml->nodecount; |
| 23 | + } |
| 24 | + } |
| 25 | + |
| 26 | + std::vector<unsigned long long> total_mech_count(n_memb_func); |
| 27 | + |
| 28 | +#if NRNMPI |
| 29 | + /// get global sum of all mechanism instances |
| 30 | + MPI_Allreduce(&local_mech_count[0], |
| 31 | + &total_mech_count[0], |
| 32 | + local_mech_count.size(), |
| 33 | + MPI_UNSIGNED_LONG_LONG, |
| 34 | + MPI_SUM, |
| 35 | + MPI_COMM_WORLD); |
| 36 | + |
| 37 | +#else |
| 38 | + total_mech_count = local_mech_count; |
| 39 | +#endif |
| 40 | + /// print global stats to stdout |
| 41 | + if (nrnmpi_myid == 0) { |
| 42 | + printf("\n================ MECHANISMS COUNT BY TYPE ==================\n"); |
| 43 | + printf("%4s %20s %10s\n", "Id", "Name", "Count"); |
| 44 | + for (size_t i = 0; i < total_mech_count.size(); i++) { |
| 45 | + printf("%4lu %20s %10lld\n", i, nrn_get_mechname(i), total_mech_count[i]); |
| 46 | + } |
| 47 | + printf("=============================================================\n"); |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +} // namespace coreneuron |
0 commit comments