Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

Commit 8914032

Browse files
author
Omar Awile
authored
Printing mechanism count and mech stats to log (#445)
Access feature through `--count_mechs` runtime option.
1 parent e44cbbe commit 8914032

File tree

6 files changed

+72
-1
lines changed

6 files changed

+72
-1
lines changed

coreneuron/apps/corenrn_parameters.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ corenrn_parameters::corenrn_parameters(){
4747
->check(CLI::Range(0., 1e9));
4848
app.add_flag("--show");
4949
app.add_set("--verbose", this->verbose, {verbose_level::NONE, verbose_level::ERROR, verbose_level::INFO, verbose_level::DEBUG}, "Verbose level: 0 = NONE, 1 = ERROR, 2 = INFO, 3 = DEBUG. Default is INFO");
50+
app.add_flag("--count_mechs", this->count_mechs, "Print number of instances of each mechanism.");
5051

5152
auto sub_gpu = app.add_option_group("GPU", "Commands relative to GPU.");
5253
sub_gpu -> add_option("-W, --nwarp", this->nwarp, "Number of warps to balance.", true)

coreneuron/apps/corenrn_parameters.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ struct corenrn_parameters {
8787

8888
bool show_version=false; /// Print version and exit.
8989

90+
bool count_mechs=false; /// Print mechanism counts after initialization
91+
9092
verbose_level verbose{verbose_level::DEFAULT}; /// Verbosity-level
9193

9294
double tstop=100; /// Stop time of simulation in msec

coreneuron/io/mech_report.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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

coreneuron/io/mech_report.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#ifndef NRN_MECH_REPORT_UTILS
2+
#define NRN_MECH_REPORT_UTILS
3+
4+
#include <string>
5+
6+
namespace coreneuron {
7+
/// write mechanism counts to stdout
8+
void write_mech_report();
9+
}
10+
11+
#endif

coreneuron/io/nrn_setup.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ THE POSSIBILITY OF SUCH DAMAGE.
5151
#include "coreneuron/utils/nrnoc_aux.hpp"
5252
#include "coreneuron/io/phase1.hpp"
5353
#include "coreneuron/io/phase2.hpp"
54+
#include "coreneuron/io/mech_report.h"
55+
#include "coreneuron/apps/corenrn_parameters.hpp"
5456

5557
// callbacks into nrn/src/nrniv/nrnbbcore_write.cpp
5658
#include "coreneuron/sim/fast_imem.hpp"
@@ -563,6 +565,9 @@ void nrn_setup(const char* filesdat,
563565
if (nrnmpi_myid == 0 && !corenrn_param.is_quiet()) {
564566
printf(" Setup Done : %.2lf seconds \n", nrn_wtime() - time);
565567
}
568+
if (corenrn_param.count_mechs) {
569+
write_mech_report();
570+
}
566571
}
567572

568573
void setup_ThreadData(NrnThread& nt) {

tests/integration/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# =============================================================================
66

77
set(COMMON_ARGS "--tstop 100. --celsius 6.3 --mpi")
8+
set(COUNT_MECHS_ARG "--count_mechs")
89
set(RING_DATASET_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ring")
910
set(RING_COMMON_ARGS "--datpath ${RING_DATASET_DIR} ${COMMON_ARGS}")
1011
set(RING_GAP_COMMON_ARGS "--datpath ${CMAKE_CURRENT_SOURCE_DIR}/ring_gap ${COMMON_ARGS}")
@@ -16,7 +17,7 @@ endif()
1617

1718
# List of tests with arguments
1819
set(TEST_CASES_WITH_ARGS
19-
"ring!${RING_COMMON_ARGS} ${GPU_ARGS} --outpath ${CMAKE_CURRENT_BINARY_DIR}/ring"
20+
"ring!${RING_COMMON_ARGS} ${COUNT_MECHS_ARG} ${GPU_ARGS} --outpath ${CMAKE_CURRENT_BINARY_DIR}/ring"
2021
"ring_binqueue!${RING_COMMON_ARGS} ${GPU_ARGS} --outpath ${CMAKE_CURRENT_BINARY_DIR}/ring_binqueue --binqueue"
2122
"ring_multisend!${RING_COMMON_ARGS} ${GPU_ARGS} --outpath ${CMAKE_CURRENT_BINARY_DIR}/ring_multisend --multisend"
2223
"ring_spike_buffer!${RING_COMMON_ARGS} ${GPU_ARGS} --outpath ${CMAKE_CURRENT_BINARY_DIR}/ring_spike_buffer --spikebuf 1"

0 commit comments

Comments
 (0)