Skip to content

Commit

Permalink
Update exspec.cc
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeshingles committed Oct 25, 2024
1 parent 8054d8b commit e7efd6b
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions exspec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ void do_angle_bin(const int a, Packet *pkts, bool load_allrank_packets, Spectra
if (a == -1 || !load_allrank_packets) {
char pktfilename[MAXFILENAMELENGTH];
snprintf(pktfilename, MAXFILENAMELENGTH, "packets%.2d_%.4d.out", 0, p);
printout("reading %s (file %d of %d)\n", pktfilename, p + 1, globals::nprocs_exspec);
printoutln2("reading {} (file {} of {})", pktfilename, p + 1, globals::nprocs_exspec);

if (std::filesystem::exists(pktfilename)) {
read_packets(pktfilename, pkts_start);
} else {
printout(" WARNING %s does not exist - trying temp packets file at beginning of timestep %d...\n",
pktfilename, globals::timestep_initial);
printoutln2(" WARNING {} does not exist - trying temp packets file at beginning of timestep {}...",
pktfilename, globals::timestep_initial);
read_temp_packetsfile(globals::timestep_initial, p, pkts_start);
}
}
Expand All @@ -74,7 +74,7 @@ void do_angle_bin(const int a, Packet *pkts, bool load_allrank_packets, Spectra
#endif

if (p % globals::nprocs != globals::rank_global) {
printout("skipping packets file %d %d\n", p + 1, globals::nprocs);
printoutln2("skipping packets file {} {}", p + 1, globals::nprocs);
continue;
}

Expand All @@ -100,8 +100,8 @@ void do_angle_bin(const int a, Packet *pkts, bool load_allrank_packets, Spectra
}
}
if (a == -1 || !load_allrank_packets) {
printout(" %d of %d packets escaped (%d gamma-pkts and %d r-pkts)\n", nesc_tot, globals::npkts, nesc_gamma,
nesc_rpkt);
printoutln2(" {} of {} packets escaped ({} gamma-pkts and {} r-pkts)", nesc_tot, globals::npkts, nesc_gamma,
nesc_rpkt);
}
}

Expand All @@ -119,7 +119,7 @@ void do_angle_bin(const int a, Packet *pkts, bool load_allrank_packets, Spectra

write_spectrum("gamma_spec.out", "", "", "", gamma_spectra, globals::ntimesteps);

printout("finished angle-averaged stuff\n");
printoutln2("finished angle-averaged stuff");
} else {
// direction bin a
// line-of-sight dependent spectra and light curves
Expand Down Expand Up @@ -156,7 +156,7 @@ void do_angle_bin(const int a, Packet *pkts, bool load_allrank_packets, Spectra
write_specpol(specpol_filename, emissionpol_filename, absorptionpol_filename, &stokes_i, &stokes_q, &stokes_u);
}

printout("Did %d of %d angle bins.\n", a + 1, MABINS);
printoutln2("Did {} of {} angle bins.", a + 1, MABINS);
}
}

Expand All @@ -180,16 +180,16 @@ auto main(int argc, char *argv[]) -> int { // NOLINT(misc-unused-parameters)
assert_always(output_file.is_open());
}

printout("git branch %s\n", GIT_BRANCH);
printoutln2("git branch {}", GIT_BRANCH);

printout("git version: %s\n", GIT_VERSION);
printoutln2("git version: {}", GIT_VERSION);

printout("git status %s\n", GIT_STATUS);
printoutln2("git status {}", GIT_STATUS);

printout("exspec compiled at %s on %s\n", __TIME__, __DATE__);
printoutln2("exspec compiled at {} on {}", __TIME__, __DATE__);

#if defined TESTMODE && TESTMODE
printout("TESTMODE is ON\n");
printoutln2("TESTMODE is ON");
#endif

#ifdef MPI_ON
Expand All @@ -199,33 +199,34 @@ auto main(int argc, char *argv[]) -> int { // NOLINT(misc-unused-parameters)
printout(" rank_in_node %d of [0..%d] in node %d of [0..%d]\n", globals::rank_in_node, globals::node_nprocs - 1,
globals::node_id, globals::node_count - 1);
#else
printout("MPI is disabled in this build\n");
printoutln2("MPI is disabled in this build");
#endif

// single rank only for now
assert_always(globals::rank_global == 0);
assert_always(globals::nprocs == 1);

printout("Beginning exspec.\n");
printoutln2("Beginning exspec.");

// Get input stuff
printout("time before input %ld\n", std::time(nullptr));
printoutln2("time before input {}", std::time(nullptr));
input(globals::rank_global);
printout("time after input %ld\n", std::time(nullptr));
printoutln2("time after input {}", std::time(nullptr));

// nprocs_exspec is the number of rank output files to process with expec
// however, we might be running exspec with 1 or just a few ranks

auto *pkts = static_cast<Packet *>(malloc(globals::nprocs_exspec * globals::npkts * sizeof(Packet)));
const bool load_allrank_packets = (pkts != nullptr);
if (load_allrank_packets) {
printout("mem_usage: loading %d packets from each %d processes simultaneously (total %d packets, %.1f MB memory)\n",
globals::npkts, globals::nprocs_exspec, globals::nprocs_exspec * globals::npkts,
globals::nprocs_exspec * globals::npkts * sizeof(Packet) / 1024. / 1024.);
printoutln2(
"mem_usage: loading {} packets from each {} processes simultaneously (total {} packets, {:.1f} MB memory)",
globals::npkts, globals::nprocs_exspec, globals::nprocs_exspec * globals::npkts,
globals::nprocs_exspec * globals::npkts * sizeof(Packet) / 1024. / 1024.);
} else {
printout("mem_usage: malloc failed to allocate memory for all packets\n");
printout(
"mem_usage: loading %d packets from each of %d processes sequentially (total %d packets, %.1f MB memory)\n",
printoutln2("mem_usage: malloc failed to allocate memory for all packets");
printoutln2(
"mem_usage: loading {} packets from each of {} processes sequentially (total {} packets, {:.1f} MB memory)",
globals::npkts, globals::nprocs_exspec, globals::nprocs_exspec * globals::npkts,
globals::nprocs_exspec * globals::npkts * sizeof(Packet) / 1024. / 1024.);
pkts = static_cast<Packet *>(malloc(globals::npkts * sizeof(Packet)));
Expand All @@ -252,7 +253,7 @@ auto main(int argc, char *argv[]) -> int { // NOLINT(misc-unused-parameters)

free(pkts);
decay::cleanup();
printout("exspec finished at %ld (tstart + %ld seconds)\n", std::time(nullptr), std::time(nullptr) - sys_time_start);
printoutln2("exspec finished at {} (tstart + {} seconds)", std::time(nullptr), std::time(nullptr) - sys_time_start);

#ifdef MPI_ON
MPI_Finalize();
Expand Down

0 comments on commit e7efd6b

Please sign in to comment.