-
Notifications
You must be signed in to change notification settings - Fork 247
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
ParallelUtils::SetNumThreads is being ignored in MKL #10183
Comments
We should update to the last version of MKL, as since 2020 they have changed many things in MKL |
We may need to set the number of threads with I have no pardiso so I cannot test, but the changes should be the following:
// System includes
#include <algorithm>
#include <cstdlib> // for std::getenv
// External includes
#ifdef KRATOS_USING_MKL
#include "mkl.h"
#endif
// Project includes
#include "parallel_utilities.h"
#include "input_output/logger.h"
#include "includes/lock_object.h" and void ParallelUtilities::SetNumThreads(const int NumThreads)
{
KRATOS_ERROR_IF(NumThreads <= 0) << "Attempting to set NumThreads to <= 0. This is not allowed" << std::endl;
#ifdef KRATOS_SMP_NONE
// do nothing if is shared memory parallelization is disabled
return;
#endif
const int num_procs = GetNumProcs();
KRATOS_WARNING_IF("ParallelUtilities", NumThreads > num_procs) << "The number of requested threads (" << NumThreads << ") exceeds the number of available threads (" << num_procs << ")!" << std::endl;
GetNumberOfThreads() = NumThreads;
#ifdef KRATOS_SMP_OPENMP
// external libraries included in Kratos still use OpenMP (such as AMGCL)
// this makes sure that they use the same number of threads as Kratos itself.
omp_set_num_threads(NumThreads);
#endif
#ifdef KRATOS_USING_MKL
mkl_set_num_threads(NumThreads);
#endif
} If this does not work tell me. |
Nice! |
I would consider a different value for MKL, as depending on the AMD processor, the multithreading doesn't work. Personal experience with a Ryzen |
No, this interface has no logic behind. We are not responsible of checking if the value makes sense. If you want to add logic to determine the best number it has to be done in the user side. |
I'm guessing |
Yep, did not remember about that. Also probably you have to parse |
argh that's nasty. What happens if both are defined? |
I suppose that
And if |
Fine by me, provided that |
I will think abt this some more, but a big blocker with including this in the core is that if Kratos is compiled with MKL then we need to distribute it always with it The same problem with MPI lead to the creation of the MPICore Different proposal: when the LinearSolversApp is compiled with MKL it could register a lambda fct in the Core which is called in SetNumThreads (and internally can call mkl_set...) |
Not on the technical side, but isn’t Intel MKL free to use even for commercial purposes? The whole Intel oneAPI? Or am I totally off topic… |
@philbucher Yea that would work, but even if we do it inside the core, it would not be a problem if its included like the other TPL. @mpentek Is free to use and redistribute, but is not compatible with BDS, they have their own ISSL licence. As with tetgen, we can distribute but the problem is for people wanting to include Kratos in their own projects. |
@roigcarlo I only partially understand. The argumentation is perhaps along these lines: daanzu/kaldi-active-grammar#47. I assume Altair has a specific issue due to including Kratos (with a BSD) license in their own project, where additionally including MKL (with ISSL) starts to become conflicting. Without lengthening this thread unnecessarily, I understand this does not affect using Kratos and MKL for our typical purposes, where we do not use these as part of another project with additional licensing requirements. |
I don't know the altair case in particular, but I think is no problem for them (they want to use it, they simply want to be able to set the threads correctly), but as a rule of thumb we cannot include in our code other codes (or parts of it) that are under licences not compatible with BDS without at least letting the user to decide if they want that code to be compiled or not. Essentially is what the discussion says. This is were the macro enters. That being said, we are hopping to release Kratos with Intel libs ourselves, so is not that we are against or anyting. We just want to make sure that you can still use Kratos in its BSD form. @RiccardoRossi has suggested me to look into the pardiso interface so maybe we can solve this without touching the core. I will see if its possible tomorrow |
@roigcarlo I tried your proposal but I am getting a linking error:
|
It's lacking @KratosMultiphysics/technical-committee At this point I would vote for enabling one-api directly in the core. We alreade have several users that need that, and we are even moving towards that ourselves (see #9912 for example for TBB and MKL...) |
That's why I added: #10185 |
I don't like to depend on Intel... |
@ddiezrod In the meantime try to force call that in the solver interfaces in @loumalouomega @philbucher I am open to other solutions. How do you suggest to approach this. I think that no one here hates intel more than I do, but please bear in mind that in windows is virtually impossible to run 1M+ element cases without TBB+MKL. (We are speaking of days vs minutes) |
I know it's absolutely proprietary™, but apart from that what's the problem with Intel and its software? (not a rhetorical question, I haven't had much experience with them yet) |
Windows!!! |
@roigcarlo I tried adding that call in eigen_direct_solver (it seems eigen_pardiso_lu was not actually being called) and it behaves as it should, using only the number of threads I assigned there. (I did not need to set MKL_NUM_THREADS in the env) |
i am not positive of having a strong dependency on blas in the core. even less so with a proprietary implementation (mkl) |
Just to confirm that if I add this block
in kratos CMakeLists, things work fine in the original design proposed by @roigcarlo |
I am not sure I get your points @RiccardoRossi @philbucher , why do you not like the first solution @roigcarlo proposed here? I do not see why that would mean adding an external dependency. If -DUSE_EIGEN_MKL is off everything works exactly as it used to. |
maybe i mosunderstood, but i thought you want to include it in the core...
if you include the function in the app i am fine with it
…On Tue, Aug 30, 2022, 12:08 Daniel Diez ***@***.***> wrote:
I am not sure I get your points @RiccardoRossi
<https://github.com/RiccardoRossi> @philbucher
<https://github.com/philbucher> , why do you not like the first solution
@roigcarlo <https://github.com/roigcarlo> proposed here? I do not see why
that would mean adding an external dependency. If -DUSE_EIGEN_MKL is off
everything works exactly as it used to.
—
Reply to this email directly, view it on GitHub
<#10183 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB5PWEORWWKC72BR2OHTYJLV3XMQZANCNFSM57LILIPA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
I don't understand what anyone means by including MKL in the core. The situation as I see it is as follows: Currently we are able to compile the LinearSolversApp with MKL. The support for MKL is provided at eigensolvers library level, and for what it matters, from Kratos we have 0 knowledge of what features of MKL are being used or not inside said lib. It appears that one of such features is the usage of intel's own implementation of OMP (KOMP). From Kratos we have an abstraction level to select the backend we want to use for SMP. So far there is full support for GOMP, and partial support for In order to solve this, we have two choices:
My suggestion was to go for 2 for several different reasons:
As I see it, this only adds options for a user compiling Kratos in their own environments, while it needs virtually no effort from our side. |
i think we are discussing in two different directions. inagine you are u using tje core alone. you would be setting the number of threads in one way. now you add pardiso. why should the core be aware of that addition? one can set the numer of threads in mkl or in the given lib by an env var no? |
Think of it from the perspective of an application:
As I see it, But that doesn't work for something as essential as multithreading, because it's used in |
i see what you say...but this will multiply the number of compilation options to smthg unmanageable. anyhow, we ll discuss this in @KratosMultiphysics/technical-committee |
@ddiezrod do we need this for Pardiso only? Then we may change the Pardiso's interface. |
In my case I only need it for pardiso yes... |
Description
I found that even if I call ParallelUtils::SetNumThreads with NumThreads=1, pardiso is still running with more threads. It only works if I manually set OMP_NUM_THREADS=1 before launching the solver. This is quite bad for us in @KratosMultiphysics/altair as the license cost is proportional to the number of threads that are being used, so we have to solve this quickly.
Any idea on how to solve this? @RiccardoRossi @philbucher @roigcarlo @pooyan-dadvand
The text was updated successfully, but these errors were encountered: