diff --git a/src/GPU/fix_gpu.cpp b/src/GPU/fix_gpu.cpp index cdcaaa8458..1117ef8eab 100644 --- a/src/GPU/fix_gpu.cpp +++ b/src/GPU/fix_gpu.cpp @@ -145,7 +145,7 @@ void FixGPU::min_setup(int vflag) void FixGPU::post_force(int vflag) { - timer->stamp(); + timer->stamp(Timer::MODIFY); double lvirial[6]; for (int i = 0; i < 6; i++) lvirial[i] = 0.0; double my_eng = lmp_gpu_forces(atom->f, atom->torque, force->pair->eatom, @@ -161,7 +161,7 @@ void FixGPU::post_force(int vflag) force->pair->virial[5] += lvirial[5]; if (force->pair->vflag_fdotr) force->pair->virial_fdotr_compute(); - timer->stamp(TIME_PAIR); + timer->stamp(Timer::PAIR); } /* ---------------------------------------------------------------------- */ diff --git a/src/REPLICA/neb.cpp b/src/REPLICA/neb.cpp index 6768b89acd..5b28e3ba61 100644 --- a/src/REPLICA/neb.cpp +++ b/src/REPLICA/neb.cpp @@ -215,7 +215,7 @@ void NEB::run() // break induced if converged // damped dynamic min styles insure all replicas converge together - timer->barrier_start(TIME_LOOP); + timer->barrier_start(Timer::LOOP); while (update->minimize->niter < n1steps) { update->minimize->run(nevery); @@ -223,7 +223,7 @@ void NEB::run() if (update->minimize->stop_condition) break; } - timer->barrier_stop(TIME_LOOP); + timer->barrier_stop(Timer::LOOP); update->minimize->cleanup(); @@ -284,14 +284,14 @@ void NEB::run() // break induced if converged // damped dynamic min styles insure all replicas converge together - timer->barrier_start(TIME_LOOP); + timer->barrier_start(Timer::LOOP); while (update->minimize->niter < n2steps) { update->minimize->run(nevery); print_status(); if (update->minimize->stop_condition) break; } - timer->barrier_stop(TIME_LOOP); + timer->barrier_stop(Timer::LOOP); update->minimize->cleanup(); diff --git a/src/REPLICA/prd.cpp b/src/REPLICA/prd.cpp index 85d1b49062..b6e03ed3a1 100644 --- a/src/REPLICA/prd.cpp +++ b/src/REPLICA/prd.cpp @@ -261,8 +261,8 @@ void PRD::command(int narg, char **arg) quench(); ncoincident = 0; share_event(0,0); - timer->barrier_start(TIME_LOOP); - time_start = timer->array[TIME_LOOP]; + timer->barrier_start(Timer::LOOP); + time_start = timer->get_wall(Timer::LOOP); log_event(); // do full init/setup since are starting all replicas after event @@ -286,8 +286,8 @@ void PRD::command(int narg, char **arg) nbuild = ndanger = 0; time_dephase = time_dynamics = time_quench = time_comm = time_output = 0.0; - timer->barrier_start(TIME_LOOP); - time_start = timer->array[TIME_LOOP]; + timer->barrier_start(Timer::LOOP); + time_start = timer->get_wall(Timer::LOOP); while (update->ntimestep < update->endstep) { dephase(); @@ -342,7 +342,7 @@ void PRD::command(int narg, char **arg) lmp->init(); update->integrate->setup(); - timer->barrier_start(TIME_LOOP); + timer->barrier_start(Timer::LOOP); if (t_corr > 0) replicate(ireplica); if (temp_flag == 0) { if (ireplica == universe->iworld) @@ -350,29 +350,29 @@ void PRD::command(int narg, char **arg) MPI_Bcast(&temp_dephase,1,MPI_DOUBLE,universe->root_proc[ireplica], universe->uworld); } - timer->barrier_stop(TIME_LOOP); - time_comm += timer->array[TIME_LOOP]; + timer->barrier_stop(Timer::LOOP); + time_comm += timer->get_wall(Timer::LOOP); // write restart file of hot coords if (restart_flag) { - timer->barrier_start(TIME_LOOP); + timer->barrier_start(Timer::LOOP); output->write_restart(update->ntimestep); - timer->barrier_stop(TIME_LOOP); - time_output += timer->array[TIME_LOOP]; + timer->barrier_stop(Timer::LOOP); + time_output += timer->get_wall(Timer::LOOP); } } // set total timers and counters so Finish() will process them - timer->array[TIME_LOOP] = time_start; - timer->barrier_stop(TIME_LOOP); + timer->set_wall(Timer::LOOP, time_start); + timer->barrier_stop(Timer::LOOP); - timer->array[TIME_PAIR] = time_dephase; - timer->array[TIME_BOND] = time_dynamics; - timer->array[TIME_KSPACE] = time_quench; - timer->array[TIME_COMM] = time_comm; - timer->array[TIME_OUTPUT] = time_output; + timer->set_wall(Timer::PAIR, time_dephase); + timer->set_wall(Timer::BOND, time_dynamics); + timer->set_wall(Timer::KSPACE, time_quench); + timer->set_wall(Timer::COMM, time_comm); + timer->set_wall(Timer::OUTPUT, time_output); neighbor->ncalls = nbuild; neighbor->ndanger = ndanger; @@ -382,12 +382,12 @@ void PRD::command(int narg, char **arg) fprintf(universe->uscreen, "Loop time of %g on %d procs for %d steps with " BIGINT_FORMAT " atoms\n", - timer->array[TIME_LOOP],nprocs_universe,nsteps,atom->natoms); + timer->get_wall(Timer::LOOP),nprocs_universe,nsteps,atom->natoms); if (universe->ulogfile) fprintf(universe->ulogfile, "Loop time of %g on %d procs for %d steps with " BIGINT_FORMAT " atoms\n", - timer->array[TIME_LOOP],nprocs_universe,nsteps,atom->natoms); + timer->get_wall(Timer::LOOP),nprocs_universe,nsteps,atom->natoms); } finish->end(2); @@ -432,7 +432,7 @@ void PRD::dephase() update->whichflag = 1; update->nsteps = n_dephase*t_dephase; - timer->barrier_start(TIME_LOOP); + timer->barrier_start(Timer::LOOP); for (int i = 0; i < n_dephase; i++) { int seed = static_cast (random_dephase->uniform() * MAXSMALLINT); @@ -442,8 +442,8 @@ void PRD::dephase() if (temp_flag == 0) temp_dephase = temperature->compute_scalar(); } - timer->barrier_stop(TIME_LOOP); - time_dephase += timer->array[TIME_LOOP]; + timer->barrier_stop(Timer::LOOP); + time_dephase += timer->get_wall(Timer::LOOP); update->integrate->cleanup(); finish->end(0); @@ -471,10 +471,10 @@ void PRD::dynamics() //modify->addstep_compute_all(update->ntimestep); int ncalls = neighbor->ncalls; - timer->barrier_start(TIME_LOOP); + timer->barrier_start(Timer::LOOP); update->integrate->run(t_event); - timer->barrier_stop(TIME_LOOP); - time_dynamics += timer->array[TIME_LOOP]; + timer->barrier_stop(Timer::LOOP); + time_dynamics += timer->get_wall(Timer::LOOP); nbuild += neighbor->ncalls - ncalls; ndanger += neighbor->ndanger; @@ -513,10 +513,10 @@ void PRD::quench() int ncalls = neighbor->ncalls; - timer->barrier_start(TIME_LOOP); + timer->barrier_start(Timer::LOOP); update->minimize->run(maxiter); - timer->barrier_stop(TIME_LOOP); - time_quench += timer->array[TIME_LOOP]; + timer->barrier_stop(Timer::LOOP); + time_quench += timer->get_wall(Timer::LOOP); if (neighbor->ncalls == ncalls) quench_reneighbor = 0; else quench_reneighbor = 1; @@ -549,7 +549,7 @@ int PRD::check_event(int replica_num) if (compute_event->compute_scalar() > 0.0) worldflag = 1; if (replica_num >= 0 && replica_num != universe->iworld) worldflag = 0; - timer->barrier_start(TIME_LOOP); + timer->barrier_start(Timer::LOOP); if (me == 0) MPI_Allreduce(&worldflag,&universeflag,1, MPI_INT,MPI_SUM,comm_replica); MPI_Bcast(&universeflag,1,MPI_INT,0,world); @@ -571,8 +571,8 @@ int PRD::check_event(int replica_num) MPI_INT,MPI_SUM,comm_replica); MPI_Bcast(&ireplica,1,MPI_INT,0,world); } - timer->barrier_stop(TIME_LOOP); - time_comm += timer->array[TIME_LOOP]; + timer->barrier_stop(Timer::LOOP); + time_comm += timer->get_wall(Timer::LOOP); return ireplica; } @@ -587,14 +587,14 @@ int PRD::check_event(int replica_num) void PRD::share_event(int ireplica, int flag) { - timer->barrier_start(TIME_LOOP); + timer->barrier_start(Timer::LOOP); // communicate quenched coords to all replicas and store as event // decrement event counter if flag = 0 since not really an event replicate(ireplica); - timer->barrier_stop(TIME_LOOP); - time_comm += timer->array[TIME_LOOP]; + timer->barrier_stop(Timer::LOOP); + time_comm += timer->get_wall(Timer::LOOP); // adjust time for last correlated event check (not on first event) @@ -629,21 +629,21 @@ void PRD::share_event(int ireplica, int flag) // addstep_compute_all insures eng/virial are calculated if needed if (output->ndump && universe->iworld == 0) { - timer->barrier_start(TIME_LOOP); + timer->barrier_start(Timer::LOOP); modify->addstep_compute_all(update->ntimestep); update->integrate->setup_minimal(1); output->write_dump(update->ntimestep); - timer->barrier_stop(TIME_LOOP); - time_output += timer->array[TIME_LOOP]; + timer->barrier_stop(Timer::LOOP); + time_output += timer->get_wall(Timer::LOOP); } // restore and communicate hot coords to all replicas fix_event->restore_state(); - timer->barrier_start(TIME_LOOP); + timer->barrier_start(Timer::LOOP); replicate(ireplica); - timer->barrier_stop(TIME_LOOP); - time_comm += timer->array[TIME_LOOP]; + timer->barrier_stop(Timer::LOOP); + time_comm += timer->get_wall(Timer::LOOP); } /* ---------------------------------------------------------------------- @@ -652,13 +652,13 @@ void PRD::share_event(int ireplica, int flag) void PRD::log_event() { - timer->array[TIME_LOOP] = time_start; + timer->set_wall(Timer::LOOP, time_start); if (universe->me == 0) { if (universe->uscreen) fprintf(universe->uscreen, BIGINT_FORMAT " %.3f %d %d %d %d %d\n", fix_event->event_timestep, - timer->elapsed(TIME_LOOP), + timer->elapsed(Timer::LOOP), fix_event->clock, fix_event->event_number,fix_event->correlated_event, fix_event->ncoincident, @@ -667,7 +667,7 @@ void PRD::log_event() fprintf(universe->ulogfile, BIGINT_FORMAT " %.3f %d %d %d %d %d\n", fix_event->event_timestep, - timer->elapsed(TIME_LOOP), + timer->elapsed(Timer::LOOP), fix_event->clock, fix_event->event_number,fix_event->correlated_event, fix_event->ncoincident, diff --git a/src/REPLICA/tad.cpp b/src/REPLICA/tad.cpp index 8241d407a7..0dd2590715 100644 --- a/src/REPLICA/tad.cpp +++ b/src/REPLICA/tad.cpp @@ -252,8 +252,8 @@ void TAD::command(int narg, char **arg) // if (universe->iworld == 0) { fix_event->store_state(); quench(); - timer->barrier_start(TIME_LOOP); - time_start = timer->array[TIME_LOOP]; + timer->barrier_start(Timer::LOOP); + time_start = timer->get_wall(Timer::LOOP); fix_event->store_event_tad(update->ntimestep); log_event(0); fix_event->restore_state(); @@ -273,8 +273,8 @@ void TAD::command(int narg, char **arg) nbuild = ndanger = 0; time_neb = time_dynamics = time_quench = time_comm = time_output = 0.0; - timer->barrier_start(TIME_LOOP); - time_start = timer->array[TIME_LOOP]; + timer->barrier_start(Timer::LOOP); + time_start = timer->get_wall(Timer::LOOP); int confident_flag, event_flag; @@ -345,10 +345,10 @@ void TAD::command(int narg, char **arg) // write restart file of hot coords if (restart_flag) { - timer->barrier_start(TIME_LOOP); + timer->barrier_start(Timer::LOOP); output->write_restart(update->ntimestep); - timer->barrier_stop(TIME_LOOP); - time_output += timer->array[TIME_LOOP]; + timer->barrier_stop(Timer::LOOP); + time_output += timer->get_wall(Timer::LOOP); } } @@ -379,14 +379,14 @@ void TAD::command(int narg, char **arg) // set total timers and counters so Finish() will process them - timer->array[TIME_LOOP] = time_start; - timer->barrier_stop(TIME_LOOP); + timer->set_wall(Timer::LOOP, time_start; + timer->barrier_stop(Timer::LOOP); - timer->array[TIME_PAIR] = time_neb; - timer->array[TIME_BOND] = time_dynamics; - timer->array[TIME_KSPACE] = time_quench; - timer->array[TIME_COMM] = time_comm; - timer->array[TIME_OUTPUT] = time_output; + timer->set_wall(Timer::PAIR, time_neb); + timer->set_wall(Timer::BOND, time_dynamics); + timer->set_wall(Timer::KSPACE, time_quench); + timer->set_wall(Timer::COMM, time_comm); + timer->set_wall(Timer::OUTPUT, time_output); neighbor->ncalls = nbuild; neighbor->ndanger = ndanger; @@ -396,12 +396,12 @@ void TAD::command(int narg, char **arg) fprintf(universe->uscreen, "Loop time of %g on %d procs for %d steps with " BIGINT_FORMAT " atoms\n", - timer->array[TIME_LOOP],nprocs_universe,nsteps,atom->natoms); + timer->get_wall(Timer::LOOP),nprocs_universe,nsteps,atom->natoms); if (universe->ulogfile) fprintf(universe->ulogfile, "Loop time of %g on %d procs for %d steps with " BIGINT_FORMAT " atoms\n", - timer->array[TIME_LOOP],nprocs_universe,nsteps,atom->natoms); + timer->get_wall(Timer::LOOP),nprocs_universe,nsteps,atom->natoms); } if (me_universe == 0) fclose(ulogfile_neb); @@ -442,10 +442,10 @@ void TAD::dynamics() //modify->addstep_compute_all(update->ntimestep); int ncalls = neighbor->ncalls; - timer->barrier_start(TIME_LOOP); + timer->barrier_start(Timer::LOOP); update->integrate->run(t_event); - timer->barrier_stop(TIME_LOOP); - time_dynamics += timer->array[TIME_LOOP]; + timer->barrier_stop(Timer::LOOP); + time_dynamics += timer->get_wall(Timer::LOOP); nbuild += neighbor->ncalls - ncalls; ndanger += neighbor->ndanger; @@ -484,10 +484,10 @@ void TAD::quench() int ncalls = neighbor->ncalls; - timer->barrier_start(TIME_LOOP); + timer->barrier_start(Timer::LOOP); update->minimize->run(maxiter); - timer->barrier_stop(TIME_LOOP); - time_quench += timer->array[TIME_LOOP]; + timer->barrier_stop(Timer::LOOP); + time_quench += timer->get_wall(Timer::LOOP); if (neighbor->ncalls == ncalls) quench_reneighbor = 0; else quench_reneighbor = 1; @@ -526,14 +526,14 @@ int TAD::check_event() void TAD::log_event(int ievent) { - timer->array[TIME_LOOP] = time_start; + timer->set_wall(Timer::LOOP, time_start); if (universe->me == 0) { double tfrac = 0.0; if (universe->uscreen) fprintf(universe->uscreen, BIGINT_FORMAT " %.3f %d %d %s %.3f %.3f %.3f %.3f\n", fix_event->event_timestep, - timer->elapsed(TIME_LOOP), + timer->elapsed(Timer::LOOP), fix_event->event_number,ievent, "E ", fix_event->ebarrier,tfrac, @@ -542,7 +542,7 @@ void TAD::log_event(int ievent) fprintf(universe->ulogfile, BIGINT_FORMAT " %.3f %d %d %s %.3f %.3f %.3f %.3f\n", fix_event->event_timestep, - timer->elapsed(TIME_LOOP), + timer->elapsed(Timer::LOOP), fix_event->event_number,ievent, "E ", fix_event->ebarrier,tfrac, @@ -554,12 +554,12 @@ void TAD::log_event(int ievent) // addstep_compute_all insures eng/virial are calculated if needed if (output->ndump && universe->iworld == 0) { - timer->barrier_start(TIME_LOOP); + timer->barrier_start(Timer::LOOP); modify->addstep_compute_all(update->ntimestep); update->integrate->setup_minimal(1); output->write_dump(update->ntimestep); - timer->barrier_stop(TIME_LOOP); - time_output += timer->array[TIME_LOOP]; + timer->barrier_stop(Timer::LOOP); + time_output += timer->get_wall(Timer::LOOP); } } @@ -747,10 +747,10 @@ void TAD::perform_neb(int ievent) // because timer->array is reset // inside neb->run() -// timer->barrier_start(TIME_LOOP); +// timer->barrier_start(Timer::LOOP); // neb->run(); -// timer->barrier_stop(TIME_LOOP); -// time_neb += timer->array[TIME_LOOP]; +// timer->barrier_stop(Timer::LOOP); +// time_neb += timer->get_wall(Timer::LOOP); MPI_Barrier(world); double time_tmp = MPI_Wtime(); @@ -943,7 +943,7 @@ void TAD::compute_tlo(int ievent) // first-replica output about each event - timer->array[TIME_LOOP] = time_start; + timer->get_wall(Timer::LOOP) = time_start; if (universe->me == 0) { double tfrac = 0.0; if (ievent > 0) tfrac = delthi/deltstop; @@ -952,7 +952,7 @@ void TAD::compute_tlo(int ievent) fprintf(universe->uscreen, BIGINT_FORMAT " %.3f %d %d %s %.3f %.3f %.3f %.3f\n", fix_event_list[ievent]->event_timestep, - timer->elapsed(TIME_LOOP), + timer->elapsed(Timer::LOOP), fix_event->event_number, ievent,statstr,ebarrier,tfrac, fix_event->tlo,deltlo); @@ -961,7 +961,7 @@ void TAD::compute_tlo(int ievent) fprintf(universe->ulogfile, BIGINT_FORMAT " %.3f %d %d %s %.3f %.3f %.3f %.3f\n", fix_event_list[ievent]->event_timestep, - timer->elapsed(TIME_LOOP), + timer->elapsed(Timer::LOOP), fix_event->event_number, ievent,statstr,ebarrier,tfrac, fix_event->tlo,deltlo); diff --git a/src/REPLICA/temper.cpp b/src/REPLICA/temper.cpp index ea8fcfaab6..f03acd22a7 100644 --- a/src/REPLICA/temper.cpp +++ b/src/REPLICA/temper.cpp @@ -203,7 +203,7 @@ void Temper::command(int narg, char **arg) print_status(); } - timer->barrier_start(TIME_LOOP); + timer->barrier_start(Timer::LOOP); for (int iswap = 0; iswap < nswaps; iswap++) { @@ -308,7 +308,7 @@ void Temper::command(int narg, char **arg) if (me_universe == 0) print_status(); } - timer->barrier_stop(TIME_LOOP); + timer->barrier_stop(Timer::LOOP); update->integrate->cleanup(); diff --git a/src/USER-CUDA/verlet_cuda.cpp b/src/USER-CUDA/verlet_cuda.cpp index 1a75e55de3..f272cc1a18 100644 --- a/src/USER-CUDA/verlet_cuda.cpp +++ b/src/USER-CUDA/verlet_cuda.cpp @@ -612,7 +612,7 @@ void VerletCuda::run(int n) clock_gettime(CLOCK_REALTIME,&starttime); timer->stamp(); comm->forward_comm(1); - timer->stamp(TIME_COMM); + timer->stamp(Timer::COMM); clock_gettime(CLOCK_REALTIME,&endtime); cuda->shared_data.cuda_timings.comm_forward_total+= endtime.tv_sec-starttime.tv_sec+1.0*(endtime.tv_nsec-starttime.tv_nsec)/1000000000; @@ -631,7 +631,7 @@ void VerletCuda::run(int n) cuda->shared_data.comm.comm_phase=1; // printf("Pre Force Compute\n"); force->pair->compute(eflag, vflag); - timer->stamp(TIME_PAIR); + timer->stamp(Timer::PAIR); //CudaWrapper_Sync(); //download comm buffers from GPU, perform MPI communication and upload buffers again @@ -641,12 +641,12 @@ void VerletCuda::run(int n) clock_gettime(CLOCK_REALTIME,&endtime); cuda->shared_data.cuda_timings.comm_forward_total+= endtime.tv_sec-starttime.tv_sec+1.0*(endtime.tv_nsec-starttime.tv_nsec)/1000000000; - timer->stamp(TIME_COMM); + timer->stamp(Timer::COMM); //wait for force calculation //printf("Pre Synch\n"); CudaWrapper_Sync(); - timer->stamp(TIME_PAIR); + timer->stamp(Timer::PAIR); //unpack communication buffers clock_gettime(CLOCK_REALTIME,&starttime); @@ -657,7 +657,7 @@ void VerletCuda::run(int n) cuda->shared_data.cuda_timings.comm_forward_total+= endtime.tv_sec-starttime.tv_sec+1.0*(endtime.tv_nsec-starttime.tv_nsec)/1000000000; - timer->stamp(TIME_COMM); + timer->stamp(Timer::COMM); MYDBG( printf("# CUDA VerletCuda::iterate: communicate done\n"); ) cuda->shared_data.cuda_timings.test1+= endtotal.tv_sec-starttotal.tv_sec+1.0*(endtotal.tv_nsec-starttotal.tv_nsec)/1000000000; @@ -672,7 +672,7 @@ void VerletCuda::run(int n) //printf("Forward_comm_done\n"); cuda->shared_data.cuda_timings.comm_forward_total+= endtime.tv_sec-starttime.tv_sec+1.0*(endtime.tv_nsec-starttime.tv_nsec)/1000000000; - timer->stamp(TIME_COMM); + timer->stamp(Timer::COMM); MYDBG( printf("# CUDA VerletCuda::iterate: communicate done\n"); ) } } @@ -756,7 +756,7 @@ void VerletCuda::run(int n) cuda->shared_data.buffer_new=2; if(atom->molecular) cuda->cu_molecule->download(); MYDBG( printf("# CUDA VerletCuda::iterate: neighbor build\n"); ) - timer->stamp(TIME_COMM); + timer->stamp(Timer::COMM); clock_gettime(CLOCK_REALTIME,&endtime); cuda->shared_data.cuda_timings.test2+= endtime.tv_sec-starttime.tv_sec+1.0*(endtime.tv_nsec-starttime.tv_nsec)/1000000000; @@ -764,7 +764,7 @@ void VerletCuda::run(int n) //rebuild neighbor list test_atom(testatom,"Pre Neighbor"); neighbor->build(); - timer->stamp(TIME_NEIGHBOR); + timer->stamp(Timer::NEIGHBOR); MYDBG( printf("# CUDA VerletCuda::iterate: neighbor done\n"); ) //if bonded interactions are used (in this case collect_forces_later is true), transfer data which only changes upon exchange/border routines from GPU to CPU @@ -851,7 +851,7 @@ void VerletCuda::run(int n) if(not cuda->shared_data.pair.collect_forces_later) CudaWrapper_Sync(); - timer->stamp(TIME_PAIR); + timer->stamp(Timer::PAIR); } //calculate bonded interactions @@ -861,14 +861,14 @@ void VerletCuda::run(int n) if(n_pre_force==0) Verlet::force_clear(); else cuda->cu_f->downloadAsync(2); - timer->stamp(TIME_PAIR); + timer->stamp(Timer::PAIR); test_atom(testatom,"pre bond force"); if(force->bond) force->bond->compute(eflag, vflag); if(force->angle) force->angle->compute(eflag, vflag); if(force->dihedral) force->dihedral->compute(eflag, vflag); if(force->improper) force->improper->compute(eflag, vflag); - timer->stamp(TIME_BOND); + timer->stamp(Timer::BOND); } //collect forces in case pair force and bonded interactions were overlapped, and either no KSPACE or a GPU KSPACE style is used @@ -887,7 +887,7 @@ void VerletCuda::run(int n) if(eflag) cuda->cu_eng_vdwl->download(); if(eflag) cuda->cu_eng_coul->download(); if(vflag) cuda->cu_virial->download(); - timer->stamp(TIME_PAIR); + timer->stamp(Timer::PAIR); clock_gettime(CLOCK_REALTIME,&endtime); cuda->shared_data.cuda_timings.pair_force_collection+= @@ -905,13 +905,13 @@ void VerletCuda::run(int n) if(n_pre_force==0) Verlet::force_clear(); else cuda->cu_f->downloadAsync(2); - timer->stamp(TIME_PAIR); + timer->stamp(Timer::PAIR); } force->kspace->compute(eflag,vflag); if((not cuda->shared_data.pppm.cudable_force) && (not cuda->shared_data.pair.collect_forces_later)) cuda->uploadAll(); - timer->stamp(TIME_KSPACE); + timer->stamp(Timer::KSPACE); } //collect forces in case pair forces and kspace was overlaped @@ -928,7 +928,7 @@ void VerletCuda::run(int n) if(eflag) cuda->cu_eng_vdwl->download(); if(eflag) cuda->cu_eng_coul->download(); if(vflag) cuda->cu_virial->download(); - timer->stamp(TIME_PAIR); + timer->stamp(Timer::PAIR); clock_gettime(CLOCK_REALTIME,&endtime); cuda->shared_data.cuda_timings.pair_force_collection+= @@ -939,7 +939,7 @@ void VerletCuda::run(int n) if(force->newton) { comm->reverse_comm(); - timer->stamp(TIME_COMM); + timer->stamp(Timer::COMM); } test_atom(testatom,"post force"); // force modifications, final time integration, diagnostics @@ -964,7 +964,7 @@ void VerletCuda::run(int n) cuda->downloadAll(); timer->stamp(); output->write(ntimestep); - timer->stamp(TIME_OUTPUT); + timer->stamp(Timer::OUTPUT); } diff --git a/src/finish.cpp b/src/finish.cpp index 52fc2f312c..d2fdd05655 100644 --- a/src/finish.cpp +++ b/src/finish.cpp @@ -46,7 +46,7 @@ void Finish::end(int flag) int histo[10]; int loopflag,minflag,prdflag,tadflag,timeflag,fftflag,histoflag,neighflag; double time,tmp,ave,max,min; - double time_loop,time_other; + double time_loop,time_other,time_cpu; int me,nprocs; MPI_Comm_rank(world,&me); @@ -73,12 +73,13 @@ void Finish::end(int flag) // loop stats if (loopflag) { - time_other = timer->array[TIME_LOOP] - - (timer->array[TIME_PAIR] + timer->array[TIME_BOND] + - timer->array[TIME_KSPACE] + timer->array[TIME_NEIGHBOR] + - timer->array[TIME_COMM] + timer->array[TIME_OUTPUT]); + time_other = timer->get_wall(Timer::LOOP) - + (timer->get_wall(Timer::PAIR) + timer->get_wall(Timer::BOND) + + timer->get_wall(Timer::KSPACE) + timer->get_wall(Timer::NEIGHBOR) + + timer->get_wall(Timer::COMM) + timer->get_wall(Timer::OUTPUT) + + timer->get_wall(Timer::MODIFY)); - time_loop = timer->array[TIME_LOOP]; + time_loop = timer->get_wall(Timer::LOOP); MPI_Allreduce(&time_loop,&tmp,1,MPI_DOUBLE,MPI_SUM,world); time_loop = tmp/nprocs; @@ -177,7 +178,7 @@ void Finish::end(int flag) if (screen) fprintf(screen,"PRD stats:\n"); if (logfile) fprintf(logfile,"PRD stats:\n"); - time = timer->array[TIME_PAIR]; + time = timer->get_wall(Timer::PAIR); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); time = tmp/nprocs; if (me == 0) { @@ -189,7 +190,7 @@ void Finish::end(int flag) time,time/time_loop*100.0); } - time = timer->array[TIME_BOND]; + time = timer->get_wall(Timer::BOND); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); time = tmp/nprocs; if (me == 0) { @@ -201,7 +202,7 @@ void Finish::end(int flag) time,time/time_loop*100.0); } - time = timer->array[TIME_KSPACE]; + time = timer->get_wall(Timer::KSPACE); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); time = tmp/nprocs; if (me == 0) { @@ -237,7 +238,7 @@ void Finish::end(int flag) if (screen) fprintf(screen,"TAD stats:\n"); if (logfile) fprintf(logfile,"TAD stats:\n"); - time = timer->array[TIME_PAIR]; + time = timer->get_wall(Timer::PAIR); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); time = tmp/nprocs; if (me == 0) { @@ -249,7 +250,7 @@ void Finish::end(int flag) time,time/time_loop*100.0); } - time = timer->array[TIME_BOND]; + time = timer->get_wall(Timer::BOND); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); time = tmp/nprocs; if (me == 0) { @@ -261,7 +262,7 @@ void Finish::end(int flag) time,time/time_loop*100.0); } - time = timer->array[TIME_KSPACE]; + time = timer->get_wall(Timer::KSPACE); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); time = tmp/nprocs; if (me == 0) { @@ -274,7 +275,7 @@ void Finish::end(int flag) } - time = timer->array[TIME_COMM]; + time = timer->get_wall(Timer::COMM); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); time = tmp/nprocs; if (me == 0) { @@ -287,7 +288,7 @@ void Finish::end(int flag) } - time = timer->array[TIME_OUTPUT]; + time = timer->get_wall(Timer::OUTPUT); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); time = tmp/nprocs; if (me == 0) { @@ -320,9 +321,22 @@ void Finish::end(int flag) if (logfile) fprintf(logfile,"\n"); } - time = timer->array[TIME_PAIR]; + time = timer->get_wall(Timer::PAIR); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); time = tmp/nprocs; +#if defined(_OPENMP) + time_cpu = timer->get_cpu(Timer::PAIR); + MPI_Allreduce(&time_cpu,&tmp,1,MPI_DOUBLE,MPI_SUM,world); + time_cpu = tmp/nprocs; + if (me == 0) { + if (screen) + fprintf(screen,"Pair time (%%) = %g (%g) (%%CPU = %g)\n", + time,time/time_loop*100.0,time_cpu/time*100.0); + if (logfile) + fprintf(logfile,"Pair time (%%) = %g (%g) (%%CPU = %g)\n", + time,time/time_loop*100.0,time_cpu/time*100.0); + } +#else if (me == 0) { if (screen) fprintf(screen,"Pair time (%%) = %g (%g)\n", @@ -331,9 +345,10 @@ void Finish::end(int flag) fprintf(logfile,"Pair time (%%) = %g (%g)\n", time,time/time_loop*100.0); } +#endif if (atom->molecular) { - time = timer->array[TIME_BOND]; + time = timer->get_wall(Timer::BOND); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); time = tmp/nprocs; if (me == 0) { @@ -347,7 +362,7 @@ void Finish::end(int flag) } if (force->kspace) { - time = timer->array[TIME_KSPACE]; + time = timer->get_wall(Timer::KSPACE); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); time = tmp/nprocs; if (me == 0) { @@ -360,7 +375,7 @@ void Finish::end(int flag) } } - time = timer->array[TIME_NEIGHBOR]; + time = timer->get_wall(Timer::NEIGHBOR); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); time = tmp/nprocs; if (me == 0) { @@ -372,7 +387,7 @@ void Finish::end(int flag) time,time/time_loop*100.0); } - time = timer->array[TIME_COMM]; + time = timer->get_wall(Timer::COMM); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); time = tmp/nprocs; if (me == 0) { @@ -384,7 +399,7 @@ void Finish::end(int flag) time,time/time_loop*100.0); } - time = timer->array[TIME_OUTPUT]; + time = timer->get_wall(Timer::OUTPUT); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); time = tmp/nprocs; if (me == 0) { @@ -396,6 +411,18 @@ void Finish::end(int flag) time,time/time_loop*100.0); } + time = timer->get_wall(Timer::MODIFY); + MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); + time = tmp/nprocs; + if (me == 0) { + if (screen) + fprintf(screen,"Modfy time (%%) = %g (%g)\n", + time,time/time_loop*100.0); + if (logfile) + fprintf(logfile,"Modfy time (%%) = %g (%g)\n", + time,time/time_loop*100.0); + } + time = time_other; MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); time = tmp/nprocs; @@ -432,7 +459,7 @@ void Finish::end(int flag) MPI_Allreduce(&time1d,&tmp,1,MPI_DOUBLE,MPI_SUM,world); time1d = tmp/nprocs; - double time_kspace = timer->array[TIME_KSPACE]; + double time_kspace = timer->get_wall(Timer::KSPACE); MPI_Allreduce(&time_kspace,&tmp,1,MPI_DOUBLE,MPI_SUM,world); time_kspace = tmp/nprocs; diff --git a/src/min.cpp b/src/min.cpp index 7ae69fbb64..1a507de0df 100644 --- a/src/min.cpp +++ b/src/min.cpp @@ -421,9 +421,13 @@ double Min::energy_force(int resetflag) if (nflag == 0) { timer->stamp(); comm->forward_comm(); - timer->stamp(TIME_COMM); + timer->stamp(Timer::COMM); } else { - if (modify->n_min_pre_exchange) modify->min_pre_exchange(); + if (modify->n_min_pre_exchange) { + timer->stamp(); + modify->min_pre_exchange(); + timer->stamp(Timer::MODIFY); + } if (triclinic) domain->x2lamda(atom->nlocal); domain->pbc(); if (domain->box_change) { @@ -437,20 +441,24 @@ double Min::energy_force(int resetflag) update->ntimestep >= atom->nextsort) atom->sort(); comm->borders(); if (triclinic) domain->lamda2x(atom->nlocal+atom->nghost); - timer->stamp(TIME_COMM); + timer->stamp(Timer::COMM); neighbor->build(); - timer->stamp(TIME_NEIGHBOR); + timer->stamp(Timer::NEIGHBOR); } ev_set(update->ntimestep); force_clear(); - if (modify->n_min_pre_force) modify->min_pre_force(vflag); timer->stamp(); + if (modify->n_min_pre_force) { + modify->min_pre_force(vflag); + timer->stamp(Timer::MODIFY); + } + if (force->pair) { force->pair->compute(eflag,vflag); - timer->stamp(TIME_PAIR); + timer->stamp(Timer::PAIR); } if (atom->molecular) { @@ -458,17 +466,17 @@ double Min::energy_force(int resetflag) if (force->angle) force->angle->compute(eflag,vflag); if (force->dihedral) force->dihedral->compute(eflag,vflag); if (force->improper) force->improper->compute(eflag,vflag); - timer->stamp(TIME_BOND); + timer->stamp(Timer::BOND); } if (force->kspace) { force->kspace->compute(eflag,vflag); - timer->stamp(TIME_KSPACE); + timer->stamp(Timer::KSPACE); } if (force->newton) { comm->reverse_comm(); - timer->stamp(TIME_COMM); + timer->stamp(Timer::COMM); } // update per-atom minimization variables stored by pair styles @@ -479,7 +487,11 @@ double Min::energy_force(int resetflag) // fixes that affect minimization - if (modify->n_min_post_force) modify->min_post_force(vflag); + if (modify->n_min_post_force) { + timer->stamp(); + modify->min_post_force(vflag); + timer->stamp(Timer::MODIFY); + } // compute potential energy of system // normalize if thermo PE does diff --git a/src/min_cg.cpp b/src/min_cg.cpp index 9ef3c8c4a7..f34db0a80a 100644 --- a/src/min_cg.cpp +++ b/src/min_cg.cpp @@ -179,7 +179,7 @@ int MinCG::iterate(int maxiter) if (output->next == ntimestep) { timer->stamp(); output->write(ntimestep); - timer->stamp(TIME_OUTPUT); + timer->stamp(Timer::OUTPUT); } } diff --git a/src/min_fire.cpp b/src/min_fire.cpp index 0c4e73dc26..7a6de6c400 100644 --- a/src/min_fire.cpp +++ b/src/min_fire.cpp @@ -265,7 +265,7 @@ int MinFire::iterate(int maxiter) if (output->next == ntimestep) { timer->stamp(); output->write(ntimestep); - timer->stamp(TIME_OUTPUT); + timer->stamp(Timer::OUTPUT); } } diff --git a/src/min_hftn.cpp b/src/min_hftn.cpp index 99c8cef3b6..af795246eb 100644 --- a/src/min_hftn.cpp +++ b/src/min_hftn.cpp @@ -536,7 +536,7 @@ int MinHFTN::execute_hftn_(const bool bPrintProgress, } timer->stamp(); output->write (update->ntimestep); - timer->stamp (TIME_OUTPUT); + timer->stamp (Timer::OUTPUT); } //---- RETURN IF NUMBER OF EVALUATIONS EXCEEDED. diff --git a/src/min_quickmin.cpp b/src/min_quickmin.cpp index 5ed10f8634..c9c1bd6e8b 100644 --- a/src/min_quickmin.cpp +++ b/src/min_quickmin.cpp @@ -232,7 +232,7 @@ int MinQuickMin::iterate(int maxiter) if (output->next == ntimestep) { timer->stamp(); output->write(ntimestep); - timer->stamp(TIME_OUTPUT); + timer->stamp(Timer::OUTPUT); } } diff --git a/src/min_sd.cpp b/src/min_sd.cpp index 02020f83db..106473c5f7 100644 --- a/src/min_sd.cpp +++ b/src/min_sd.cpp @@ -100,7 +100,7 @@ int MinSD::iterate(int maxiter) if (output->next == ntimestep) { timer->stamp(); output->write(ntimestep); - timer->stamp(TIME_OUTPUT); + timer->stamp(Timer::OUTPUT); } } diff --git a/src/minimize.cpp b/src/minimize.cpp index dcee996dc0..d28b788108 100644 --- a/src/minimize.cpp +++ b/src/minimize.cpp @@ -53,9 +53,9 @@ void Minimize::command(int narg, char **arg) lmp->init(); update->minimize->setup(); - timer->barrier_start(TIME_LOOP); + timer->barrier_start(Timer::LOOP); update->minimize->run(update->nsteps); - timer->barrier_stop(TIME_LOOP); + timer->barrier_stop(Timer::LOOP); update->minimize->cleanup(); diff --git a/src/respa.cpp b/src/respa.cpp index 9786b2875e..76fd20fc6c 100644 --- a/src/respa.cpp +++ b/src/respa.cpp @@ -455,13 +455,17 @@ void Respa::run(int n) recurse(nlevels-1); - if (modify->n_end_of_step) modify->end_of_step(); + if (modify->n_end_of_step) { + timer->stamp(); + modify->end_of_step(); + timer->stamp(Timer::MODIFY); + } if (ntimestep == output->next) { timer->stamp(); sum_flevel_f(); output->write(update->ntimestep); - timer->stamp(TIME_OUTPUT); + timer->stamp(Timer::OUTPUT); } } } @@ -493,9 +497,11 @@ void Respa::recurse(int ilevel) for (int iloop = 0; iloop < loop[ilevel]; iloop++) { + timer->stamp(); modify->initial_integrate_respa(vflag,ilevel,iloop); if (modify->n_post_integrate_respa) modify->post_integrate_respa(ilevel,iloop); + timer->stamp(Timer::MODIFY); if (ilevel) recurse(ilevel-1); @@ -506,7 +512,11 @@ void Respa::recurse(int ilevel) if (ilevel == nlevels-1) { int nflag = neighbor->decide(); if (nflag) { - if (modify->n_pre_exchange) modify->pre_exchange(); + if (modify->n_pre_exchange) { + timer->stamp(); + modify->pre_exchange(); + timer->stamp(Timer::MODIFY); + } if (triclinic) domain->x2lamda(atom->nlocal); domain->pbc(); if (domain->box_change) { @@ -520,68 +530,76 @@ void Respa::recurse(int ilevel) update->ntimestep >= atom->nextsort) atom->sort(); comm->borders(); if (triclinic) domain->lamda2x(atom->nlocal+atom->nghost); - timer->stamp(TIME_COMM); - if (modify->n_pre_neighbor) modify->pre_neighbor(); + timer->stamp(Timer::COMM); + if (modify->n_pre_neighbor) { + modify->pre_neighbor(); + timer->stamp(Timer::MODIFY); + } neighbor->build(); - timer->stamp(TIME_NEIGHBOR); + timer->stamp(Timer::NEIGHBOR); } } else if (ilevel == 0) { timer->stamp(); comm->forward_comm(); - timer->stamp(TIME_COMM); + timer->stamp(Timer::COMM); } force_clear(newton[ilevel]); - if (modify->n_pre_force_respa) + if (modify->n_pre_force_respa) { + timer->stamp(); modify->pre_force_respa(vflag,ilevel,iloop); + timer->stamp(Timer::MODIFY); + } timer->stamp(); if (level_bond == ilevel && force->bond) { force->bond->compute(eflag,vflag); - timer->stamp(TIME_BOND); + timer->stamp(Timer::BOND); } if (level_angle == ilevel && force->angle) { force->angle->compute(eflag,vflag); - timer->stamp(TIME_BOND); + timer->stamp(Timer::BOND); } if (level_dihedral == ilevel && force->dihedral) { force->dihedral->compute(eflag,vflag); - timer->stamp(TIME_BOND); + timer->stamp(Timer::BOND); } if (level_improper == ilevel && force->improper) { force->improper->compute(eflag,vflag); - timer->stamp(TIME_BOND); + timer->stamp(Timer::BOND); } if (level_pair == ilevel && force->pair) { force->pair->compute(eflag,vflag); - timer->stamp(TIME_PAIR); + timer->stamp(Timer::PAIR); } if (level_inner == ilevel && force->pair) { force->pair->compute_inner(); - timer->stamp(TIME_PAIR); + timer->stamp(Timer::PAIR); } if (level_middle == ilevel && force->pair) { force->pair->compute_middle(); - timer->stamp(TIME_PAIR); + timer->stamp(Timer::PAIR); } if (level_outer == ilevel && force->pair) { force->pair->compute_outer(eflag,vflag); - timer->stamp(TIME_PAIR); + timer->stamp(Timer::PAIR); } if (level_kspace == ilevel && force->kspace) { force->kspace->compute(eflag,vflag); - timer->stamp(TIME_KSPACE); + timer->stamp(Timer::KSPACE); } if (newton[ilevel]) { comm->reverse_comm(); - timer->stamp(TIME_COMM); + timer->stamp(Timer::COMM); } + timer->stamp(); if (modify->n_post_force_respa) modify->post_force_respa(vflag,ilevel,iloop); modify->final_integrate_respa(ilevel,iloop); + timer->stamp(Timer::MODIFY); } copy_f_flevel(ilevel); diff --git a/src/run.cpp b/src/run.cpp index 667ea84a80..00183cd7cc 100644 --- a/src/run.cpp +++ b/src/run.cpp @@ -176,9 +176,9 @@ void Run::command(int narg, char **arg) output->setup(0); } - timer->barrier_start(TIME_LOOP); + timer->barrier_start(Timer::LOOP); update->integrate->run(nsteps); - timer->barrier_stop(TIME_LOOP); + timer->barrier_stop(Timer::LOOP); update->integrate->cleanup(); @@ -216,9 +216,9 @@ void Run::command(int narg, char **arg) output->setup(0); } - timer->barrier_start(TIME_LOOP); + timer->barrier_start(Timer::LOOP); update->integrate->run(nsteps); - timer->barrier_stop(TIME_LOOP); + timer->barrier_stop(Timer::LOOP); update->integrate->cleanup(); diff --git a/src/thermo.cpp b/src/thermo.cpp index 1653de8f42..4a407ac2c7 100644 --- a/src/thermo.cpp +++ b/src/thermo.cpp @@ -323,7 +323,7 @@ void Thermo::compute(int flag) int loc = 0; if (lineflag == MULTILINE) { double cpu; - if (flag) cpu = timer->elapsed(TIME_LOOP); + if (flag) cpu = timer->elapsed(Timer::LOOP); else cpu = 0.0; loc = sprintf(&line[loc],format_multi,ntimestep,cpu); } @@ -1427,7 +1427,7 @@ void Thermo::compute_dt() void Thermo::compute_cpu() { if (firststep == 0) dvalue = 0.0; - else dvalue = timer->elapsed(TIME_LOOP); + else dvalue = timer->elapsed(Timer::LOOP); } /* ---------------------------------------------------------------------- */ @@ -1441,7 +1441,7 @@ void Thermo::compute_tpcpu() new_cpu = 0.0; dvalue = 0.0; } else { - new_cpu = timer->elapsed(TIME_LOOP); + new_cpu = timer->elapsed(Timer::LOOP); double cpu_diff = new_cpu - last_tpcpu; double time_diff = new_time - last_time; if (time_diff > 0.0 && cpu_diff > 0.0) dvalue = time_diff/cpu_diff; @@ -1463,7 +1463,7 @@ void Thermo::compute_spcpu() new_cpu = 0.0; dvalue = 0.0; } else { - new_cpu = timer->elapsed(TIME_LOOP); + new_cpu = timer->elapsed(Timer::LOOP); double cpu_diff = new_cpu - last_spcpu; int step_diff = new_step - last_step; if (cpu_diff > 0.0) dvalue = step_diff/cpu_diff; diff --git a/src/timer.cpp b/src/timer.cpp index eb38d5d249..d323e5f8bb 100644 --- a/src/timer.cpp +++ b/src/timer.cpp @@ -15,27 +15,73 @@ #include "timer.h" #include "memory.h" +#ifndef _WIN32 +#include "sys/time.h" +#include "sys/resource.h" +#endif + using namespace LAMMPS_NS; +static double get_cpu_time() +{ +#ifndef _WIN32 + struct rusage ru; + double rv = 0.0; + if (getrusage(RUSAGE_SELF, &ru) == 0) { + rv = (double) ru.ru_utime.tv_sec; + rv += (double) ru.ru_utime.tv_usec * 0.000001; + } + return rv; +#endif + return 0.0; +} + +/* ---------------------------------------------------------------------- */ +static double get_sys_time() +{ +#ifndef _WIN32 + struct rusage ru; + double rv = 0.0; + if (getrusage(RUSAGE_SELF, &ru) == 0) { + rv = (double) ru.ru_stime.tv_sec; + rv += (double) ru.ru_stime.tv_usec * 0.000001; + } + return rv; +#endif + return 0.0; +} + +/* ---------------------------------------------------------------------- */ +static double get_wall_time() +{ + return MPI_Wtime(); +} + /* ---------------------------------------------------------------------- */ Timer::Timer(LAMMPS *lmp) : Pointers(lmp) { - memory->create(array,TIME_N,"array"); + memory->create(cpu_array,TIME_N,"timer:cpu_array"); + memory->create(sys_array,TIME_N,"timer:sys_array"); + memory->create(wall_array,TIME_N,"timer:wall_array"); } /* ---------------------------------------------------------------------- */ Timer::~Timer() { - memory->destroy(array); + memory->destroy(cpu_array); + memory->destroy(sys_array); + memory->destroy(wall_array); } /* ---------------------------------------------------------------------- */ void Timer::init() { - for (int i = 0; i < TIME_N; i++) array[i] = 0.0; + for (int i = 0; i < TIME_N; i++) cpu_array[i] = 0.0; + for (int i = 0; i < TIME_N; i++) sys_array[i] = 0.0; + for (int i = 0; i < TIME_N; i++) wall_array[i] = 0.0; } /* ---------------------------------------------------------------------- */ @@ -44,41 +90,79 @@ void Timer::stamp() { // uncomment if want synchronized timing // MPI_Barrier(world); - previous_time = MPI_Wtime(); + previous_cpu = get_cpu_time(); + previous_sys = get_sys_time(); + previous_wall = get_wall_time(); } /* ---------------------------------------------------------------------- */ -void Timer::stamp(int which) +void Timer::stamp(enum ttype which) { // uncomment if want synchronized timing // MPI_Barrier(world); - double current_time = MPI_Wtime(); - array[which] += current_time - previous_time; - previous_time = current_time; + double current_cpu = get_cpu_time(); + double current_sys = get_sys_time(); + double current_wall = get_wall_time(); + cpu_array[which] += current_cpu - previous_cpu; + sys_array[which] += current_sys - previous_sys; + wall_array[which] += current_wall - previous_wall; + previous_cpu = current_cpu; + previous_sys = current_sys; + previous_wall = current_wall; } /* ---------------------------------------------------------------------- */ -void Timer::barrier_start(int which) +void Timer::barrier_start(enum ttype which) { MPI_Barrier(world); - array[which] = MPI_Wtime(); + cpu_array[which] = get_cpu_time(); + sys_array[which] = get_sys_time(); + wall_array[which] = get_wall_time(); } /* ---------------------------------------------------------------------- */ -void Timer::barrier_stop(int which) +void Timer::barrier_stop(enum ttype which) { MPI_Barrier(world); - double current_time = MPI_Wtime(); - array[which] = current_time - array[which]; + double current_cpu = get_cpu_time(); + double current_sys = get_sys_time(); + double current_wall = get_wall_time(); + cpu_array[which] = current_cpu - cpu_array[which]; + sys_array[which] = current_sys - sys_array[which]; + wall_array[which] = current_wall - wall_array[which]; } /* ---------------------------------------------------------------------- */ -double Timer::elapsed(int which) +double Timer::cpu(enum ttype which) { - double current_time = MPI_Wtime(); - return (current_time - array[which]); + double current_cpu = get_cpu_time(); + return (current_cpu - cpu_array[which]); } + +/* ---------------------------------------------------------------------- */ + +double Timer::sys(enum ttype which) +{ + double current_sys = get_sys_time(); + return (current_sys - sys_array[which]); +} + +/* ---------------------------------------------------------------------- */ + +double Timer::elapsed(enum ttype which) +{ + double current_wall = get_wall_time(); + return (current_wall - wall_array[which]); +} + +/* ---------------------------------------------------------------------- */ + +void Timer::set_wall(enum ttype which, double newtime) +{ + wall_array[which] = newtime; +} + diff --git a/src/timer.h b/src/timer.h index 95851dfd23..530c4c3833 100644 --- a/src/timer.h +++ b/src/timer.h @@ -16,26 +16,40 @@ #include "pointers.h" -enum{TIME_LOOP,TIME_PAIR,TIME_BOND,TIME_KSPACE,TIME_NEIGHBOR, - TIME_COMM,TIME_OUTPUT,TIME_N}; namespace LAMMPS_NS { class Timer : protected Pointers { public: - double *array; + enum ttype {LOOP=0,PAIR,BOND,KSPACE,NEIGHBOR,COMM,MODIFY,OUTPUT,TIME_N}; Timer(class LAMMPS *); ~Timer(); void init(); void stamp(); - void stamp(int); - void barrier_start(int); - void barrier_stop(int); - double elapsed(int); + void stamp(enum ttype); + void barrier_start(enum ttype); + void barrier_stop(enum ttype); + double elapsed(enum ttype); + double cpu(enum ttype); + double sys(enum ttype); + + double get_cpu(enum ttype which) const { + return cpu_array[which]; }; + double get_sys(enum ttype which) const { + return sys_array[which]; }; + double get_wall(enum ttype which) const { + return wall_array[which]; }; + + void set_wall(enum ttype, double); private: - double previous_time; + double *cpu_array; + double *sys_array; + double *wall_array; + double previous_cpu; + double previous_sys; + double previous_wall; }; } diff --git a/src/verlet.cpp b/src/verlet.cpp index 10932c10fb..1a0b9cbd27 100644 --- a/src/verlet.cpp +++ b/src/verlet.cpp @@ -209,8 +209,10 @@ void Verlet::run(int n) // initial time integration + timer->stamp(); modify->initial_integrate(vflag); if (n_post_integrate) modify->post_integrate(); + timer->stamp(Timer::MODIFY); // regular communication vs neighbor list rebuild @@ -219,9 +221,13 @@ void Verlet::run(int n) if (nflag == 0) { timer->stamp(); comm->forward_comm(); - timer->stamp(TIME_COMM); + timer->stamp(Timer::COMM); } else { - if (n_pre_exchange) modify->pre_exchange(); + if (n_pre_exchange) { + timer->stamp(); + modify->pre_exchange(); + timer->stamp(Timer::MODIFY); + } if (triclinic) domain->x2lamda(atom->nlocal); domain->pbc(); if (domain->box_change) { @@ -234,22 +240,30 @@ void Verlet::run(int n) if (sortflag && ntimestep >= atom->nextsort) atom->sort(); comm->borders(); if (triclinic) domain->lamda2x(atom->nlocal+atom->nghost); - timer->stamp(TIME_COMM); - if (n_pre_neighbor) modify->pre_neighbor(); + timer->stamp(Timer::COMM); + if (n_pre_neighbor) { + modify->pre_neighbor(); + timer->stamp(Timer::MODIFY); + } neighbor->build(); - timer->stamp(TIME_NEIGHBOR); + timer->stamp(Timer::NEIGHBOR); } // force computations force_clear(); - if (n_pre_force) modify->pre_force(vflag); timer->stamp(); + if (n_pre_force) { + modify->pre_force(vflag); + timer->stamp(Timer::MODIFY); + } + + if (force->pair) { force->pair->compute(eflag,vflag); - timer->stamp(TIME_PAIR); + timer->stamp(Timer::PAIR); } if (atom->molecular) { @@ -257,19 +271,19 @@ void Verlet::run(int n) if (force->angle) force->angle->compute(eflag,vflag); if (force->dihedral) force->dihedral->compute(eflag,vflag); if (force->improper) force->improper->compute(eflag,vflag); - timer->stamp(TIME_BOND); + timer->stamp(Timer::BOND); } if (force->kspace) { force->kspace->compute(eflag,vflag); - timer->stamp(TIME_KSPACE); + timer->stamp(Timer::KSPACE); } // reverse communication of forces if (force->newton) { comm->reverse_comm(); - timer->stamp(TIME_COMM); + timer->stamp(Timer::COMM); } // force modifications, final time integration, diagnostics @@ -277,13 +291,14 @@ void Verlet::run(int n) if (n_post_force) modify->post_force(vflag); modify->final_integrate(); if (n_end_of_step) modify->end_of_step(); + timer->stamp(Timer::MODIFY); // all output if (ntimestep == output->next) { timer->stamp(); output->write(ntimestep); - timer->stamp(TIME_OUTPUT); + timer->stamp(Timer::OUTPUT); } } }