int colvarproxy_smp::smp_biases_script_loop() { #if defined(_OPENMP) colvarmodule *cv = cvm::main(); #pragma omp parallel { #pragma omp single nowait { cv->calc_scripted_forces(); } #pragma omp for for (size_t i = 0; i < cv->biases_active()->size(); i++) { colvarbias *b = (*(cv->biases_active()))[i]; if (cvm::debug()) { cvm::log("Calculating bias \""+b->name+"\" on thread "+ cvm::to_str(smp_thread_id())+"\n"); } b->update(); } } return cvm::get_error(); #else return COLVARS_NOT_IMPLEMENTED; #endif }
void count_register_thread(unsigned long *p) { int idx = smp_thread_id(); spin_lock(&final_mutex); countarrayp->counterp[idx] = &counter; spin_unlock(&final_mutex); }
void *thread_test(void *arg) { int myarg = (int)arg; printf("child thread %d: smp_thread_id() = %d\n", myarg, smp_thread_id()); return NULL; }
void count_unregister_thread(int nthreadsexpected) { int idx = smp_thread_id(); spin_lock(&final_mutex); finalcount += *counter; counterp[idx] = NULL; spin_unlock(&final_mutex); }
colvarproxy_smp::~colvarproxy_smp() { #if defined(_OPENMP) if (smp_thread_id() == 0) { if (omp_lock_state) { delete reinterpret_cast<omp_lock_t *>(omp_lock_state); } } #endif }
colvarproxy_smp::colvarproxy_smp() { b_smp_active = true; // May be disabled by user option omp_lock_state = NULL; #if defined(_OPENMP) if (smp_thread_id() == 0) { omp_init_lock(reinterpret_cast<omp_lock_t *>(omp_lock_state)); } #endif }
int colvarproxy_lammps::smp_biases_loop() { colvarmodule *cv = this->colvars; #pragma omp parallel for for (size_t i = 0; i < cv->biases.size(); i++) { if (cvm::debug()) { cvm::log("Calculating bias \""+cv->biases[i]->name+"\" on thread "+cvm::to_str(smp_thread_id())+"\n"); } cv->biases[i]->update(); } return cvm::get_error(); }
void count_unregister_thread(int nthreadsexpected) { struct countarray *cap; struct countarray *capold; int idx = smp_thread_id(); cap = malloc(sizeof(*countarrayp)); if (cap == NULL) { fprintf(stderr, "Out of memory\n"); exit(-1); } spin_lock(&final_mutex); *cap = *countarrayp; cap->total += counter; cap->counterp[idx] = NULL; capold = countarrayp; rcu_assign_pointer(countarrayp, cap); spin_unlock(&final_mutex); synchronize_rcu(); free(capold); }
colvarproxy_lammps::colvarproxy_lammps(LAMMPS_NS::LAMMPS *lmp, const char *inp_name, const char *out_name, const int seed, const double temp, MPI_Comm root2root) : _lmp(lmp), inter_comm(root2root) { if (cvm::debug()) log("Initializing the colvars proxy object.\n"); _random = new LAMMPS_NS::RanPark(lmp,seed); first_timestep=true; system_force_requested=false; previous_step=-1; t_target=temp; do_exit=false; restart_every=0; // User-scripted forces are not available in LAMMPS force_script_defined = false; have_scripts = false; // set input restart name and strip the extension, if present input_prefix_str = std::string(inp_name ? inp_name : ""); if (input_prefix_str.rfind(".colvars.state") != std::string::npos) input_prefix_str.erase(input_prefix_str.rfind(".colvars.state"), std::string(".colvars.state").size()); // output prefix is always given output_prefix_str = std::string(out_name); // not so for restarts restart_output_prefix_str = std::string("rest"); // check if it is possible to save output configuration if ((!output_prefix_str.size()) && (!restart_output_prefix_str.size())) { fatal_error("Error: neither the final output state file or " "the output restart file could be defined, exiting.\n"); } // try to extract a restart prefix from a potential restart command. LAMMPS_NS::Output *outp = _lmp->output; if ((outp->restart_every_single > 0) && (outp->restart1 != 0)) { restart_output_prefix_str = std::string(outp->restart1); } else if ((outp->restart_every_double > 0) && (outp->restart2a != 0)) { restart_output_prefix_str = std::string(outp->restart2a); } // trim off unwanted stuff from the restart prefix if (restart_output_prefix_str.rfind(".*") != std::string::npos) restart_output_prefix_str.erase(restart_output_prefix_str.rfind(".*"),2); #if defined(_OPENMP) if (smp_thread_id() == 0) { omp_init_lock(&smp_lock_state); } #endif // initialize multi-replica support, if available if (replica_enabled()) { MPI_Comm_rank(inter_comm, &inter_me); MPI_Comm_size(inter_comm, &inter_num); } if (cvm::debug()) log("Done initializing the colvars proxy object.\n"); }
int colvarproxy_lammps::smp_colvars_loop() { colvarmodule *cv = this->colvars; #pragma omp parallel for for (size_t i = 0; i < cv->colvars_smp.size(); i++) { if (cvm::debug()) { cvm::log("Calculating colvar \""+cv->colvars_smp[i]->name+"\" on thread "+cvm::to_str(smp_thread_id())+"\n"); } cv->colvars_smp[i]->calc_cvcs(cv->colvars_smp_items[i], 1); } return cvm::get_error(); }