Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed: need to init ewoms thread manager #1557

Merged
merged 1 commit into from
Aug 24, 2018
Merged

Conversation

akva2
Copy link
Member

@akva2 akva2 commented Aug 24, 2018

This fixes OpenMP. Not entirely sure this is where the call is wanted etc etc, but at least it points out the issue.

Without this call, manager returns 1 thread and we crash and burn in the fvbaselinearizer due to missing contexts.

@andlaus
Copy link
Contributor

andlaus commented Aug 24, 2018

jenkins build this please

@andlaus
Copy link
Contributor

andlaus commented Aug 24, 2018

the patch looks good. I'll merge if jenkins is happy with it.

@andlaus andlaus merged commit 15890a2 into OPM:master Aug 24, 2018
@akva2 akva2 deleted the fix_flow_openmp branch August 24, 2018 20:40
@alfbr
Copy link
Member

alfbr commented Aug 25, 2018

This restored the test at linuxbenchmarking.com, but the performance benefit from openmp is gone. It seems this PR disabled the threading. I can check more on Monday.

@andlaus
Copy link
Contributor

andlaus commented Aug 25, 2018

its possible that currently the only way to specify the number of threads per process for non-frankenstein simulators without OPM/opm-models#318 is using the --threads-per-process=$N command line parameter. since the flow frankenstein did not care about OpenMP until the switch to the eWoms parameter system where it got slightly less frankensteiny, setting OMP_NUM_THREADS "accidentally" worked for it.

@alfbr
Copy link
Member

alfbr commented Aug 25, 2018

So the new parameter system broke the threading implementation? Maybe it should be reverted until we can fix it?

@andlaus
Copy link
Contributor

andlaus commented Aug 25, 2018

So the new parameter system broke the threading implementation? Maybe it should be reverted until we can fix it?

I might have been wrong, but no, this PR broke OpenMP by fixing it: before it, openMP was not explicitly initialized at all. I guess this meant that the thread manager object from eWoms just returned garbage and the arrays in Ewoms::FvBaseLinearizer which depend on the number of threads were not initialized correctly. IOW, the fact that you did not get a segfault with flow was always just plain luck. (Also note that OPM/opm-models#318 never suffered from this issue.)

@blattms
Copy link
Member

blattms commented Aug 27, 2018

I beg to differ. Before the parameter system was changed OMP was correctly initialized as in parameter system PR you removed the OMP initialization in FlowMainEbos.hpp

            // OpenMP setup.
            if (!getenv("OMP_NUM_THREADS")) {
                // Default to at most 2 threads, regardless of
                // number of cores (unless ENV(OMP_NUM_THREADS) is defined)
                int num_cores = omp_get_num_procs();
                int num_threads = std::min(2, num_cores);
                omp_set_num_threads(num_threads);
            }

and

            std::string numThreadsParam("--threads-per-process=");
            int numThreads = omp_get_max_threads();
            numThreadsParam += std::to_string(numThreads);
            argv.push_back(numThreadsParam.c_str());

without calling something similar somewhere else. Now with the call to ThreadManager::init() we finally initialize set the number of threads again (omp_set_num_threads), but the number of threads still seems different. The default seems to be set to 1 now in ewoms/disc/common/fvbasediscretization.hh.

But there seem to be several ThreadsPerProcess properties:

ewoms$ find . -name \*.[hc][hc]| xargs grep ThreadsPerProcess
./ewoms/disc/common/fvbasediscretization.hh:SET_INT_PROP(FvBaseDiscretization, ThreadsPerProcess, 1);
./ewoms/disc/common/fvbaseproperties.hh:NEW_PROP_TAG(ThreadsPerProcess);
./ewoms/parallel/threadmanager.hh:NEW_PROP_TAG(ThreadsPerProcess);
./ewoms/parallel/threadmanager.hh:        EWOMS_REGISTER_PARAM(TypeTag, int, ThreadsPerProcess,
./ewoms/parallel/threadmanager.hh:        numThreads_ = EWOMS_GET_PARAM(TypeTag, int, ThreadsPerProcess);

Not sure which one rules.

@andlaus
Copy link
Contributor

andlaus commented Aug 27, 2018

You're right: the threading stuff used to be initialized correctly, albeit it only supported the OMP_NUM_THREADS method.

But there seem to be several ThreadsPerProcess properties:

The property is only set once (the first line of your grep results). the thread manager uses the corresponding parameter which uses the property as a default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants