mirror of
https://github.com/OPM/opm-simulators.git
synced 2024-11-25 10:40:21 -06:00
Merge pull request #1316 from andlaus/fix_openmp
flow_ebos: fix the OpenMP functionality
This commit is contained in:
commit
dde9db92a6
@ -78,6 +78,7 @@ namespace Opm
|
||||
public:
|
||||
typedef typename GET_PROP(TypeTag, MaterialLaw)::EclMaterialLawManager MaterialLawManager;
|
||||
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, GridView) GridView;
|
||||
typedef typename GET_PROP_TYPE(TypeTag, Problem) Problem;
|
||||
@ -167,15 +168,12 @@ namespace Opm
|
||||
int num_threads = std::min(4, num_cores);
|
||||
omp_set_num_threads(num_threads);
|
||||
}
|
||||
#pragma omp parallel
|
||||
if (omp_get_thread_num() == 0) {
|
||||
// omp_get_num_threads() only works as expected within a parallel region.
|
||||
const int num_omp_threads = omp_get_num_threads();
|
||||
if (mpi_size == 1) {
|
||||
std::cout << "OpenMP using " << num_omp_threads << " threads." << std::endl;
|
||||
} else {
|
||||
std::cout << "OpenMP using " << num_omp_threads << " threads on MPI rank " << mpi_rank_ << "." << std::endl;
|
||||
}
|
||||
// omp_get_num_threads() only works as expected within a parallel region.
|
||||
const int num_omp_threads = omp_get_max_threads();
|
||||
if (mpi_size == 1) {
|
||||
std::cout << "OpenMP using " << num_omp_threads << " threads." << std::endl;
|
||||
} else {
|
||||
std::cout << "OpenMP using " << num_omp_threads << " threads on MPI rank " << mpi_rank_ << "." << std::endl;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -410,14 +408,25 @@ namespace Opm
|
||||
|
||||
void setupEbosSimulator()
|
||||
{
|
||||
std::string progName("flow_ebos");
|
||||
std::string deckFile("--ecl-deck-file-name=");
|
||||
deckFile += param_.get<std::string>("deck_filename");
|
||||
char* ptr[2];
|
||||
ptr[ 0 ] = const_cast< char * > (progName.c_str());
|
||||
ptr[ 1 ] = const_cast< char * > (deckFile.c_str());
|
||||
std::vector<const char*> argv;
|
||||
|
||||
argv.push_back("flow_ebos");
|
||||
|
||||
std::string deckFileParam("--ecl-deck-file-name=");
|
||||
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();
|
||||
Ewoms::setupParameters_< TypeTag > ( 2, ptr );
|
||||
Ewoms::setupParameters_<TypeTag>(argv.size(), &argv[0]);
|
||||
EbosThreadManager::init();
|
||||
ebosSimulator_.reset(new EbosSimulator(/*verbose=*/false));
|
||||
ebosSimulator_->model().applyInitialSolution();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user