Skip to content

Commit

Permalink
optimized integration of workers in novikov simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
chegerland committed Mar 22, 2021
1 parent 6a0fafc commit 4b4269c
Showing 1 changed file with 47 additions and 20 deletions.
67 changes: 47 additions & 20 deletions app/spike_suscept_lin_novikov.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,41 +110,68 @@ void main_process(

BOOST_LOG_TRIVIAL(info)
<< "Calculating linear and nonlinear susceptibility.";
for (auto &simulation : simulation_array) {
simulation.calculate(trials);
for (size_t i = 0; i < simulation_array.size(); i++) {
simulation_array[i].calculate(trials);
BOOST_LOG_TRIVIAL(info) << "Finished one simulation.";
}

BOOST_LOG_TRIVIAL(info) << "Finished all calculations.";

BOOST_LOG_TRIVIAL(info) << "Receiving values from subprocesses.";
BOOST_LOG_TRIVIAL(info) << "Receiving values from subprocesses.";

// receive arrays back from subprocesses
std::vector<std::complex<double>> tmp_suscept_lin(
simulation_array[0].get_size_lin());
std::vector<std::complex<double>> tmp_suscept_nonlin(
simulation_array[0].get_size_nonlin());
// receive arrays back from subprocesses
std::vector<std::complex<double>> tmp_suscept_lin(
simulation_array[0].get_size_lin());
std::vector<std::complex<double>> tmp_suscept_nonlin(
simulation_array[0].get_size_nonlin());

MPI_Status status;
for (int i = 1; i < world_size; i++) {
for (size_t j = 0; j < simulation_array.size(); j++) {
MPI_Status status;
for (int j = 1; j < world_size; j++) {
// receive arrays
MPI_Recv(tmp_suscept_lin.data(), (int)tmp_suscept_lin.size(),
MPI_CXX_DOUBLE_COMPLEX, MPI_ANY_SOURCE, 2 * j + 2,
MPI_CXX_DOUBLE_COMPLEX, MPI_ANY_SOURCE, 2 * i + 2,
MPI_COMM_WORLD, &status);
MPI_Recv(tmp_suscept_nonlin.data(), (int)tmp_suscept_nonlin.size(),
MPI_CXX_DOUBLE_COMPLEX, MPI_ANY_SOURCE, 2 * j + 1,
MPI_CXX_DOUBLE_COMPLEX, MPI_ANY_SOURCE, 2 * i + 1,
MPI_COMM_WORLD, &status);

// add array to overall susceptibility
simulation_array[j].add_to_suscepts(tmp_suscept_lin,
simulation_array[i].add_to_suscepts(tmp_suscept_lin,
tmp_suscept_nonlin);
BOOST_LOG_TRIVIAL(info) << "Received from worker " << j;
}
BOOST_LOG_TRIVIAL(info) << "Received from worker " << i;
BOOST_LOG_TRIVIAL(info) << "All values received.";
}
BOOST_LOG_TRIVIAL(info) << "All values received.";

BOOST_LOG_TRIVIAL(info) << "Writing results to file " << output_file << ".";
BOOST_LOG_TRIVIAL(info) << "Finished all calculations.";

// BOOST_LOG_TRIVIAL(info) << "Receiving values from subprocesses.";

//// receive arrays back from subprocesses
// std::vector<std::complex<double>> tmp_suscept_lin(
// simulation_array[0].get_size_lin());
// std::vector<std::complex<double>> tmp_suscept_nonlin(
// simulation_array[0].get_size_nonlin());

// MPI_Status status;
// for (int i = 1; i < world_size; i++) {
// for (size_t j = 0; j < simulation_array.size(); j++) {
// // receive arrays
// MPI_Recv(tmp_suscept_lin.data(), (int)tmp_suscept_lin.size(),
// MPI_CXX_DOUBLE_COMPLEX, MPI_ANY_SOURCE, 2 * j + 2,
// MPI_COMM_WORLD, &status);
// MPI_Recv(tmp_suscept_nonlin.data(),
// (int)tmp_suscept_nonlin.size(),
// MPI_CXX_DOUBLE_COMPLEX, MPI_ANY_SOURCE, 2 * j + 1,
// MPI_COMM_WORLD, &status);

// // add array to overall susceptibility
// simulation_array[j].add_to_suscepts(tmp_suscept_lin,
// tmp_suscept_nonlin);
// }
// BOOST_LOG_TRIVIAL(info) << "Received from worker " << i;
//}
// BOOST_LOG_TRIVIAL(info) << "All values received.";

// BOOST_LOG_TRIVIAL(info) << "Writing results to file " << output_file <<
// ".";

// write susceptibility to file
std::ofstream file;
Expand Down

0 comments on commit 4b4269c

Please sign in to comment.