Skip to content

Commit

Permalink
Merge branch 'v2.9'
Browse files Browse the repository at this point in the history
  • Loading branch information
GiovanniBussi committed Nov 29, 2023
2 parents 1e69738 + 41e9dd5 commit dd113a1
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions regtest/basic/rt-make-threads/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,50 @@
using namespace PLMD;

void run(std::ostream & os, const std::string & name,std::function<void(int)> f,unsigned nthreads=4,unsigned nrepeats=10){

// vector containing possible error messages from threads
std::vector<std::string> msgs(nthreads);

// wrapper function that catch exceptions and store their messages
auto g=[&](int i){
try {
f(i);
} catch(const std::exception& e) {
char buffer[1024];
std::sprintf(buffer,"(thread %d)\n",i);
msgs[i]=std::string(buffer)+e.what();
}
};

os<<"Test "<<name<<" with OpenMP...\n";
{
for(unsigned i=0;i<nrepeats;i++) {
#if defined(_OPENMP)
#pragma omp parallel num_threads(nthreads)
f(omp_get_thread_num());
g(omp_get_thread_num());
#else
f(0);
g(0);
#endif
std::string msg;
for(unsigned j=0;j<nthreads;j++) if(msgs[j].length()>0) msg+=msgs[j];
// one could propagate the exception with plumed_error()<<msg;
// I instead just write the error on the os file, which will be shown in diff
// This allows running both tests (openmp here and threads below)
if(msg.length()>0) os<<"failed with error "<<msg;
msg.clear();
}
}
os<<"OK"<<std::endl;

os<<"Test "<<name<<" with C++11 threads...\n";
for(unsigned i=0;i<nrepeats;i++) {
std::vector<std::thread> threads;
for(unsigned j=0;j<nthreads;j++) threads.emplace_back(std::thread(f,j));
for(unsigned j=0;j<nthreads;j++) threads.emplace_back(std::thread(g,j));
for(unsigned j=0;j<nthreads;j++) threads[j].join();
std::string msg;
for(unsigned j=0;j<nthreads;j++) if(msgs[j].length()>0) msg+=msgs[j];
if(msg.length()>0) os<<"failed with error "<<msg;
msg.clear();
}
os<<"OK"<<std::endl;
}
Expand Down

1 comment on commit dd113a1

@PlumedBot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found broken examples in automatic/a-masterclass-22-09.txt
Found broken examples in automatic/a-masterclass-22-11.txt
Found broken examples in automatic/a-masterclass-22-12.txt
Found broken examples in automatic/performance-optimization.txt
Found broken examples in automatic/a-trieste-6.txt
Found broken examples in automatic/munster.txt
Found broken examples in automatic/ANN.tmp
Found broken examples in automatic/EDS.tmp
Found broken examples in automatic/EMMI.tmp
Found broken examples in automatic/ENVIRONMENTSIMILARITY.tmp
Found broken examples in automatic/FOURIER_TRANSFORM.tmp
Found broken examples in automatic/FUNCPATHGENERAL.tmp
Found broken examples in automatic/FUNCPATHMSD.tmp
Found broken examples in automatic/FUNNEL.tmp
Found broken examples in automatic/FUNNEL_PS.tmp
Found broken examples in automatic/GHBFIX.tmp
Found broken examples in automatic/INCLUDE.tmp
Found broken examples in automatic/MAZE_MEMETIC_SAMPLING.tmp
Found broken examples in automatic/MAZE_OPTIMIZER_BIAS.tmp
Found broken examples in automatic/MAZE_RANDOM_ACCELERATION_MD.tmp
Found broken examples in automatic/MAZE_RANDOM_WALK.tmp
Found broken examples in automatic/MAZE_SIMULATED_ANNEALING.tmp
Found broken examples in automatic/MAZE_STEERED_MD.tmp
Found broken examples in automatic/PIV.tmp
Found broken examples in automatic/PLUMED.tmp
Found broken examples in MiscelaneousPP.md

Please sign in to comment.