Skip to content
Snippets Groups Projects
Commit 2ba63476 authored by Matteo Cicuttin's avatar Matteo Cicuttin
Browse files

Reactivated CPU solver.

parent 6333fd61
No related branches found
No related tags found
No related merge requests found
...@@ -204,8 +204,8 @@ compute_rk4_weighted_sum(solver_state_gpu& state, const field_gpu& in, ...@@ -204,8 +204,8 @@ compute_rk4_weighted_sum(solver_state_gpu& state, const field_gpu& in,
void void
timestep(solver_state_gpu& state) timestep(solver_state_gpu& state)
{ {
timecounter tc; //timecounter tc;
tc.tic(); //tc.tic();
/* /*
apply_operator(state, state.emf_curr, state.tmp); apply_operator(state, state.emf_curr, state.tmp);
...@@ -228,9 +228,9 @@ timestep(solver_state_gpu& state) ...@@ -228,9 +228,9 @@ timestep(solver_state_gpu& state)
state.curr_time += state.delta_t; state.curr_time += state.delta_t;
state.curr_timestep += 1; state.curr_timestep += 1;
double time = tc.toc(); //double time = tc.toc();
double dofs_per_sec = 6*state.emf_curr.num_dofs/time; //double dofs_per_sec = 6*state.emf_curr.num_dofs/time;
std::cout << "Timestep " << state.curr_timestep << ", " << dofs_per_sec << " DOFs/s" << std::endl; //std::cout << "Timestep " << state.curr_timestep << ", " << dofs_per_sec << " DOFs/s" << std::endl;
} }
......
...@@ -61,7 +61,7 @@ void initialize_solver(const model& mod, State& state, const maxwell::parameter_ ...@@ -61,7 +61,7 @@ void initialize_solver(const model& mod, State& state, const maxwell::parameter_
} }
void void
do_boundary_sources(const model& mod, maxwell::solver_state& state, do_sources(const model& mod, maxwell::solver_state& state,
const maxwell::parameter_loader& mpl) const maxwell::parameter_loader& mpl)
{ {
maxwell::eval_boundary_sources(mod, mpl, state, state.bndsrcs); maxwell::eval_boundary_sources(mod, mpl, state, state.bndsrcs);
...@@ -69,15 +69,46 @@ do_boundary_sources(const model& mod, maxwell::solver_state& state, ...@@ -69,15 +69,46 @@ do_boundary_sources(const model& mod, maxwell::solver_state& state,
} }
void void
do_boundary_sources(const model& mod, maxwell::solver_state_gpu& state, prepare_sources(const model& mod, maxwell::solver_state& state,
const maxwell::parameter_loader& mpl)
{
do_sources(mod, state, mpl);
}
void
swap(maxwell::solver_state& state)
{
std::swap(state.emf_curr, state.emf_next);
}
#ifdef ENABLE_GPU_SOLVER
void
prepare_sources(const model& mod, maxwell::solver_state_gpu& state,
const maxwell::parameter_loader& mpl) const maxwell::parameter_loader& mpl)
{ {
maxwell::eval_boundary_sources(mod, mpl, state, state.bndsrcs_cpu); maxwell::eval_boundary_sources(mod, mpl, state, state.bndsrcs_cpu);
state.bndsrcs_buf.copyin(state.bndsrcs_cpu, state.memcpy_stream); state.bndsrcs_buf.copyin(state.bndsrcs_cpu, state.memcpy_stream);
//maxwell::eval_interface_sources(mod, mpl, state, state.bndsrcs_cpu); state.memcpy_stream.wait();
//state.memcpy_stream.wait(); std::swap(state.bndsrcs, state.bndsrcs_buf);
} }
void
do_sources(const model& mod, maxwell::solver_state_gpu& state,
const maxwell::parameter_loader& mpl)
{
maxwell::eval_boundary_sources(mod, mpl, state, state.bndsrcs_cpu);
state.bndsrcs_buf.copyin(state.bndsrcs_cpu, state.memcpy_stream);
}
void
swap(maxwell::solver_state_gpu& state)
{
cudaDeviceSynchronize();
std::swap(state.bndsrcs, state.bndsrcs_buf);
std::swap(state.emf_curr, state.emf_next);
}
#endif
template<typename State> template<typename State>
void test_it(const model& mod, State& state, const maxwell::parameter_loader& mpl) void test_it(const model& mod, State& state, const maxwell::parameter_loader& mpl)
{ {
...@@ -92,12 +123,11 @@ void test_it(const model& mod, State& state, const maxwell::parameter_loader& mp ...@@ -92,12 +123,11 @@ void test_it(const model& mod, State& state, const maxwell::parameter_loader& mp
omp_set_num_threads(4); omp_set_num_threads(4);
#endif #endif
do_boundary_sources(mod, state, mpl); prepare_sources(mod, state, mpl);
std::swap(state.bndsrcs, state.bndsrcs_buf);
for(size_t i = 0; i < num_timesteps; i++) for(size_t i = 0; i < num_timesteps; i++)
{ {
timestep(state); timestep(state);
do_boundary_sources(mod, state, mpl); do_sources(mod, state, mpl);
std::stringstream ss; std::stringstream ss;
ss << mpl.sim_name() << "/timestep_" << i << ".silo"; ss << mpl.sim_name() << "/timestep_" << i << ".silo";
...@@ -109,9 +139,7 @@ void test_it(const model& mod, State& state, const maxwell::parameter_loader& mp ...@@ -109,9 +139,7 @@ void test_it(const model& mod, State& state, const maxwell::parameter_loader& mp
std::cout << "Cycle " << i << ": t = " << state.curr_time << " s"; std::cout << "Cycle " << i << ": t = " << state.curr_time << " s";
std::cout << std::endl; std::cout << std::endl;
} }
cudaDeviceSynchronize(); swap(state);
std::swap(state.bndsrcs, state.bndsrcs_buf);
std::swap(state.emf_curr, state.emf_next);
} }
} }
...@@ -155,8 +183,8 @@ int main(int argc, const char *argv[]) ...@@ -155,8 +183,8 @@ int main(int argc, const char *argv[])
else else
{ {
#endif /* ENABLE_GPU_SOLVER */ #endif /* ENABLE_GPU_SOLVER */
//maxwell::solver_state state_c; maxwell::solver_state state_c;
//test_it(mod, state_c, mpl); test_it(mod, state_c, mpl);
#ifdef ENABLE_GPU_SOLVER #ifdef ENABLE_GPU_SOLVER
} }
#endif #endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment