flow_ebos: fix the OpenMP functionality

the ThreadManager from ebos was not called which resulted in some
havoc when attempting multi-threaded runs.

v2: use opm_get_max_threads() directly. thanks to [at]akva2 for the heads-up.
This commit is contained in:
Andreas Lauser 2017-11-02 11:19:21 +01:00
parent 53942053af
commit 36bd6a1681

View File

@ -78,6 +78,7 @@ namespace Opm
public: public:
typedef typename GET_PROP(TypeTag, MaterialLaw)::EclMaterialLawManager MaterialLawManager; typedef typename GET_PROP(TypeTag, MaterialLaw)::EclMaterialLawManager MaterialLawManager;
typedef typename GET_PROP_TYPE(TypeTag, Simulator) EbosSimulator; typedef typename GET_PROP_TYPE(TypeTag, Simulator) EbosSimulator;
typedef typename GET_PROP_TYPE(TypeTag, ThreadManager) EbosThreadManager;
typedef typename GET_PROP_TYPE(TypeTag, Grid) Grid; typedef typename GET_PROP_TYPE(TypeTag, Grid) Grid;
typedef typename GET_PROP_TYPE(TypeTag, GridView) GridView; typedef typename GET_PROP_TYPE(TypeTag, GridView) GridView;
typedef typename GET_PROP_TYPE(TypeTag, Problem) Problem; typedef typename GET_PROP_TYPE(TypeTag, Problem) Problem;
@ -167,15 +168,12 @@ namespace Opm
int num_threads = std::min(4, num_cores); int num_threads = std::min(4, num_cores);
omp_set_num_threads(num_threads); omp_set_num_threads(num_threads);
} }
#pragma omp parallel // omp_get_num_threads() only works as expected within a parallel region.
if (omp_get_thread_num() == 0) { const int num_omp_threads = omp_get_max_threads();
// omp_get_num_threads() only works as expected within a parallel region. if (mpi_size == 1) {
const int num_omp_threads = omp_get_num_threads(); std::cout << "OpenMP using " << num_omp_threads << " threads." << std::endl;
if (mpi_size == 1) { } else {
std::cout << "OpenMP using " << num_omp_threads << " threads." << std::endl; std::cout << "OpenMP using " << num_omp_threads << " threads on MPI rank " << mpi_rank_ << "." << std::endl;
} else {
std::cout << "OpenMP using " << num_omp_threads << " threads on MPI rank " << mpi_rank_ << "." << std::endl;
}
} }
#endif #endif
} }
@ -410,14 +408,25 @@ namespace Opm
void setupEbosSimulator() void setupEbosSimulator()
{ {
std::string progName("flow_ebos"); std::vector<const char*> argv;
std::string deckFile("--ecl-deck-file-name=");
deckFile += param_.get<std::string>("deck_filename"); argv.push_back("flow_ebos");
char* ptr[2];
ptr[ 0 ] = const_cast< char * > (progName.c_str()); std::string deckFileParam("--ecl-deck-file-name=");
ptr[ 1 ] = const_cast< char * > (deckFile.c_str()); deckFileParam += param_.get<std::string>("deck_filename");
argv.push_back(deckFileParam.c_str());
#if defined(_OPENMP)
std::string numThreadsParam("--threads-per-process=");
int numThreads = omp_get_max_threads();
numThreadsParam += std::to_string(numThreads);
argv.push_back(numThreadsParam.c_str());
#endif // defined(_OPENMP)
EbosSimulator::registerParameters(); EbosSimulator::registerParameters();
Ewoms::setupParameters_< TypeTag > ( 2, ptr ); Ewoms::setupParameters_<TypeTag>(argv.size(), &argv[0]);
EbosThreadManager::init();
ebosSimulator_.reset(new EbosSimulator(/*verbose=*/false)); ebosSimulator_.reset(new EbosSimulator(/*verbose=*/false));
ebosSimulator_->model().applyInitialSolution(); ebosSimulator_->model().applyInitialSolution();