/** Add one thread. * Add the given thread to the thread manager. The thread is initialized * as appropriate and started. See the class documentation for supported * specialisations of threads and the performed initialisation steps. * If the thread initializer cannot initalize the thread it is not added. * @param thread thread to add * @param lock if true the environment is locked before adding the thread * @exception CannotInitializeThreadException thrown if at least the * thread could not be initialised */ void ThreadManager::add_maybelocked(Thread *thread, bool lock) { if ( thread == NULL ) { throw NullPointerException("FawkesThreadMananger: cannot add NULL as thread"); } if ( ! (__initializer && __finalizer) ) { throw NullPointerException("ThreadManager: initializer/finalizer not set"); } try { __initializer->init(thread); } catch (CannotInitializeThreadException &e) { thread->notify_of_failed_init(); e.append("Adding thread in ThreadManager failed"); throw; } // if the thread's init() method fails, we need to finalize that very // thread only with the finalizer, already initialized threads muts be // fully finalized try { thread->init(); } catch (CannotInitializeThreadException &e) { thread->notify_of_failed_init(); __finalizer->finalize(thread); throw; } catch (Exception &e) { thread->notify_of_failed_init(); CannotInitializeThreadException cite("Could not initialize thread '%s'", thread->name()); cite.append(e); __finalizer->finalize(thread); throw cite; } catch (std::exception &e) { thread->notify_of_failed_init(); CannotInitializeThreadException cite("Could not initialize thread '%s'", thread->name()); cite.append("Caught std::exception or derivative: %s", e.what()); __finalizer->finalize(thread); throw cite; } catch (...) { thread->notify_of_failed_init(); CannotInitializeThreadException cite("Could not initialize thread '%s'", thread->name()); cite.append("Unknown exception caught"); __finalizer->finalize(thread); throw cite; } thread->start(); MutexLocker locker(__threads.mutex(), lock); internal_add_thread(thread); }
//----------------------------------------------------------------------- void ConverterPass1::XmlAnnotation(XMLElement *annotation, bool startUnit) { if (!annotation) return; if (startUnit) units_->push_back(Unit(bodyType_, Unit::ANNOTATION, 0, -1)); XmlAddId(annotation); for (XMLNode *ch = annotation->FirstChild(); ch; ch = ch->NextSibling()) { //<p>, <poem>, <cite>, <subtitle>, <empty-line>, <table> const char *tag = ch->Value(); if (!tag) continue; if (strcmp(tag, "p") == 0) p(); else if (strcmp(tag, "poem") == 0) poem(); else if (strcmp(tag, "cite") == 0) cite(); else if (strcmp(tag, "subtitle") == 0) subtitle(); else if (strcmp(tag, "empty-line") == 0) ; // do nothing here, was: empty_line(); else if (strcmp(tag, "table") == 0) table(); //</p>, </poem>, </cite>, </subtitle>, </empty-line>, </table> } }
void THashTest::TestHMMap1() { typedef yhash_multimap<char, int, THash<char>, TEqualTo<char> > mmap; mmap m; UNIT_ASSERT(m.count('X') == 0); m.insert(TPair<const char, int>('X', 10)); // Standard way. UNIT_ASSERT(m.count('X') == 1); m.insert(TPair<const char, int>('X', 20)); // jbuck: standard way UNIT_ASSERT(m.count('X') == 2); m.insert(TPair<const char, int>('Y', 32)); // jbuck: standard way mmap::iterator i = m.find('X'); // Find first match. UNIT_ASSERT((*i).first == 'X'); UNIT_ASSERT((*i).second == 10); i++; UNIT_ASSERT((*i).first == 'X'); UNIT_ASSERT((*i).second == 20); i = m.find('Y'); UNIT_ASSERT((*i).first == 'Y'); UNIT_ASSERT((*i).second == 32); i = m.find('Z'); UNIT_ASSERT(i == m.end()); size_t count = m.erase('X'); UNIT_ASSERT(count == 2); //Some iterators compare check, really compile time checks mmap::iterator ite(m.begin()); mmap::const_iterator cite(m.begin()); UNIT_ASSERT((mmap::const_iterator)ite == cite); UNIT_ASSERT(!((mmap::const_iterator)ite != cite)); UNIT_ASSERT(cite == (mmap::const_iterator)ite); UNIT_ASSERT(!(cite != (mmap::const_iterator)ite)); typedef yhash_multimap<size_t, size_t> HMapType; HMapType hmap; //We fill the map to implicitely start a rehash. for (size_t counter = 0; counter < 3077; ++counter) { hmap.insert(HMapType::value_type(1, counter)); } hmap.insert(HMapType::value_type(12325, 1)); hmap.insert(HMapType::value_type(12325, 2)); UNIT_ASSERT(hmap.count(12325) == 2); //At this point 23 goes to the same bucket as 12325, it used to reveal a bug. hmap.insert(HMapType::value_type(23, 0)); UNIT_ASSERT(hmap.count(12325) == 2); }
Bias::Bias(const ActionOptions&ao): Action(ao), ActionPilot(ao), ActionWithValue(ao), ActionWithArguments(ao), outputForces(getNumberOfArguments(),0.0) { addComponentWithDerivatives("bias"); componentIsNotPeriodic("bias"); valueBias=getPntrToComponent("bias"); if(getStride()>1) { log<<" multiple time step "<<getStride()<<" "; log<<cite("Ferrarotti, Bottaro, Perez-Villa, and Bussi, J. Chem. Theory Comput. 11, 139 (2015)")<<"\n"; } for(unsigned i=0; i<getNumberOfArguments(); ++i) { (getPntrToArgument(i)->getPntrToAction())->turnOnDerivatives(); } turnOnDerivatives(); }
void PlumedMain::init() { // check that initialization just happens once initialized=true; atoms.init(); if(!log.isOpen()) log.link(stdout); log<<"PLUMED is starting\n"; log<<"Version: "<<config::getVersionLong()<<" (git: "<<config::getVersionGit()<<") compiled on " __DATE__ " at " __TIME__ "\n"; log<<"Please cite this paper when using PLUMED "; log<<cite("Tribello, Bonomi, Branduardi, Camilloni, and Bussi, Comput. Phys. Commun. 185, 604 (2014)"); log<<"\n"; log<<"For further information see the PLUMED web page at http://www.plumed.org\n"; log<<"Root: "<<config::getPlumedRoot()<<"\n"; log<<"For installed feature, see "<<config::getPlumedRoot() + "/src/config/config.txt\n"; log.printf("Molecular dynamics engine: %s\n",MDEngine.c_str()); log.printf("Precision of reals: %d\n",atoms.getRealPrecision()); log.printf("Running over %d %s\n",comm.Get_size(),(comm.Get_size()>1?"nodes":"node")); log<<"Number of threads: "<<OpenMP::getNumThreads()<<"\n"; log<<"Cache line size: "<<OpenMP::getCachelineSize()<<"\n"; log.printf("Number of atoms: %d\n",atoms.getNatoms()); if(grex) log.printf("GROMACS-like replica exchange is on\n"); log.printf("File suffix: %s\n",getSuffix().c_str()); if(plumedDat.length()>0) { readInputFile(plumedDat); plumedDat=""; } atoms.updateUnits(); log.printf("Timestep: %f\n",atoms.getTimeStep()); if(atoms.getKbT()>0.0) log.printf("KbT: %f\n",atoms.getKbT()); else { log.printf("KbT has not been set by the MD engine\n"); log.printf("It should be set by hand where needed\n"); } log<<"Relevant bibliography:\n"; log<<citations; log<<"Please read and cite where appropriate!\n"; log<<"Finished setup\n"; }
void THashTest::TestHMap1() { typedef yhash_map<char, Stroka, THash<char>, TEqualTo<char> > maptype; maptype m; // Store mappings between roman numerals and decimals. m['l'] = "50"; m['x'] = "20"; // Deliberate mistake. m['v'] = "5"; m['i'] = "1"; UNIT_ASSERT(!strcmp(m['x'].c_str(),"20")); m['x'] = "10"; // Correct mistake. UNIT_ASSERT(!strcmp(m['x'].c_str(),"10")); UNIT_ASSERT(!m.has('z')); UNIT_ASSERT(!strcmp(m['z'].c_str(),"")); UNIT_ASSERT(m.has('z')); UNIT_ASSERT(m.count('z') == 1); TPair<maptype::iterator, bool> p = m.insert(TPair<const char, Stroka>('c', Stroka("100"))); UNIT_ASSERT(p.second); p = m.insert(TPair<const char, Stroka>('c', Stroka("100"))); UNIT_ASSERT(!p.second); //Some iterators compare check, really compile time checks maptype::iterator ite(m.begin()); maptype::const_iterator cite(m.begin()); cite = m.begin(); maptype const& cm = m; cite = cm.begin(); UNIT_ASSERT((maptype::const_iterator)ite == cite); UNIT_ASSERT(!((maptype::const_iterator)ite != cite)); UNIT_ASSERT(cite == (maptype::const_iterator)ite); UNIT_ASSERT(!(cite != (maptype::const_iterator)ite)); }