1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
#include <iostream>
#include <fstream>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/foreach.hpp>
#include <RDGeneral/Invariant.h>
#include <RDGeneral/RDLog.h>
#include <RDGeneral/utils.h>
#include <RDGeneral/StreamOps.h>
#include <GraphMol/RDKitBase.h>
#include <GraphMol/MolPickler.h>
#include <GraphMol/SmilesParse/SmilesParse.h>
#include <GraphMol/FileParsers/FileParsers.h>
#include <GraphMol/FileParsers/MolSupplier.h>
#include <GraphMol/Descriptors/MolDescriptors.h>
#include <GraphMol/Descriptors/Crippen.h>
#include <DataStructs/BitVects.h>
#include <DataStructs/BitOps.h>
#include "inchi.h"
using namespace RDKit;
#ifdef RDK_TEST_MULTITHREADED
namespace {
void runblock(const std::vector<ROMol *> &mols,unsigned int count,
unsigned int idx,
std::vector<std::string> &inchis,
std::vector<std::string> &keys
){
for(unsigned int j=0;j<50;j++){
for(unsigned int i=0;i<mols.size();++i){
if(i%count != idx) continue;
ROMol *mol = mols[i];
ExtraInchiReturnValues tmp;
std::string inchi=MolToInchi(*mol,tmp);
TEST_ASSERT(inchi==inchis[i]);
std::string key=InchiToInchiKey(inchi);
TEST_ASSERT(key==keys[i]);
ROMol *mol2 = InchiToMol(inchi,tmp);
TEST_ASSERT(mol2);
ExtraInchiReturnValues tmp2;
std::string inchi2=MolToInchi(*mol2,tmp2);
TEST_ASSERT(inchi==inchi2);
delete mol2;
}
}
};
}
#include <boost/thread.hpp>
void testMultiThread(){
BOOST_LOG(rdErrorLog) << "-------------------------------------" << std::endl;
BOOST_LOG(rdErrorLog) << " Test multithreading" << std::endl;
std::string fName = getenv("RDBASE");
fName += "/Data/NCI/first_200.props.sdf";
SDMolSupplier suppl(fName);
std::cerr<<"reading molecules"<<std::endl;
std::vector<ROMol *> mols;
while(!suppl.atEnd()&&mols.size()<100){
ROMol *mol=0;
try{
mol=suppl.next();
} catch(...){
continue;
}
if(!mol) continue;
mols.push_back(mol);
}
std::cerr<<"generating reference data"<<std::endl;
std::vector<std::string> inchis;
std::vector<std::string> keys;
BOOST_FOREACH(const ROMol *mol,mols){
ExtraInchiReturnValues tmp;
std::string inchi=MolToInchi(*mol,tmp);
std::string key=InchiToInchiKey(inchi);
inchis.push_back(inchi);
keys.push_back(key);
}
boost::thread_group tg;
std::cerr<<"processing"<<std::endl;
unsigned int count=4;
for(unsigned int i=0;i<count;++i){
std::cerr<<" launch :"<<i<<std::endl;std::cerr.flush();
tg.add_thread(new boost::thread(runblock,mols,count,i,inchis,keys));
}
tg.join_all();
for(unsigned int i=0;i<mols.size();++i) delete mols[i];
BOOST_LOG(rdErrorLog) << " done" << std::endl;
}
#else
void testMultiThread(){
}
#endif
//-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
//
//-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
int main(){
RDLog::InitLogs();
testMultiThread();
}
|