-
Notifications
You must be signed in to change notification settings - Fork 248
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
[Core] Add SetRank
method to GlobalPointer
+ documentation
#11762
[Core] Add SetRank
method to GlobalPointer
+ documentation
#11762
Conversation
Why exactly do you need to change the rank of a global pointer? GP were designed to be created in the partition they belong, its hard for me to find a use case in which this construction is valid and does not lead to problems. |
Because somethimes the rank is not provided in construction time |
Well yes, but can you elaborate? how can you not have the rank in the processor its mean to create the GP? |
Because the See: d6873a9 |
if this is the problem I would personally change the GlobalPointer(TDataType data, int rank = ParallelEnvironment::GetDefaultRank()) But maybe I am biased here, ping @KratosMultiphysics/mpi |
That will not work, because creates a MPI dependency, will fail on linking time |
It does not work like that When you start Kratos with mpi, the first time the kernel is loaded you will call: # __init__.py:67
mpi.InitializeMPIParallelRun() This code lives in the MPI extension of the core, and among other things does: // Define the World DataCommunicator as a wrapper for MPI_COMM_WORLD and make it the default.
ParallelEnvironment::RegisterDataCommunicator("World", MPIDataCommunicator::Create(MPI_COMM_WORLD), ParallelEnvironment::MakeDefault); This will invoke the code from: void ParallelEnvironment::SetAsDefault(
std::unordered_map<std::string, DataCommunicator::UniquePointer>::iterator& rThisCommunicator)
{
mDefaultCommunicator = rThisCommunicator;
const auto& r_comm = *(rThisCommunicator->second);
mDefaultRank = r_comm.Rank();
mDefaultSize = r_comm.Size();
} Which will set the It does not matter that the implementation this part is MPI dependent, because it does not live in the same shared lib as the rest of KratosCore, but it will change the default registered communicator. When you call |
Btw, I will admit that |
I will try |
Well let see what the rest of people say, maybe I am being paranoid and setrank is fine for everyone... |
It is impossible, I need many forward declarations in many different classes (20 files I have right now). It is easier to just simply keet the SetRank method |
Actually, the problem is the |
yes, but I needed to change many files |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok to many things are wrong in the core. Lets accept this for now and I will take care of unraveling the kernel
Indeed..., many many cross dependencies. I think we should reconsider the forward declaration policy to begin with |
#ifdef KRATOS_USING_MPI | ||
int mRank; | ||
this->mRank = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you want to initialize it? if it is not a correct value better leave it undefined no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The diff is terrible, the code was already like that , see line 48 in previous implementation
* @param Rank The rank to set | ||
*/ | ||
void SetRank(const int Rank) | ||
{ | ||
#ifdef KRATOS_USING_MPI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, i guess we should have a debug error here in case we are not in mpi mode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And rank is different than 0, because if you implement a generic code in serial it will set always to 0, otherwise you will create many false errors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, imagine you try to set something to rank 5 in serial... that would be silently ignored
i am fundamentally against it! |
In that case we will have longer compilation times and cross dependencies issues all along the core |
well, we will need to solve those... forward declaration is really a dangerous thing ... |
When it is dangerous?, if a same class is defined diferently in different files?, a priori you will have linking problems |
for example the dependency check mechanism (includes) gets broken by forward declarations |
I think if you what are you doing should not be problematic, and we approve changes little by little |
well, i ping @KratosMultiphysics/technical-committee ... but i anticpate you that i am completely agains this |
I understand, but @roigcarlo also found due to this PR problems related with cross dependencies difficult to solve without this technique |
📝 Description
Add
SetRank
method toGlobalPointer
, plus adding documentation🆕 Changelog
SetRank
method toGlobalPointer
+ documentation