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

Pick 1st Value and last Value of 1D cellVariable while running in parallel #617

Closed
ACamposG opened this issue Feb 1, 2019 · 3 comments
Closed
Labels

Comments

@ACamposG
Copy link

ACamposG commented Feb 1, 2019

I have a 1D cellVariable 'X' of 100 elements, with uniformGrid1D mesh type. During execution, on every single time step I need to take the first value X[0] and the last value X[-1] and subtract them (for some purpose) : X[0] - X[-1]

When I run in parallel, I use a conditional statement with procID=0 and procID=Nproc-1 to locate the values I need as follows:

if parallel.procID == 0:
Xi=X[0]
if parallel.procID == (parallel.Nproc - 1):
Xf=X[-1]

Subtraction= Xi-Xf

However, Xi and Xf are empty, it seems that outside the conditional the variables are reset.

I tried to broadcast the value of X[0] in the first core but it does not work. It seems that sometimes the last core is executed before the first core so X[0] is not there yet.

Is there a workaround or a way to do it?

Thanks

@guyer guyer added the question label Feb 1, 2019
@guyer
Copy link
Member

guyer commented Feb 1, 2019

It's not that Xi and Xf are reset, but that they are only defined on procID == 0 and procID == (Nproc - 1), respectively.

You were on the right track with broadcasting, but not with X[0]. Rather, try

Xi = None
Xf = None
if parallel.procID == 0:
    Xi=X[0]
if parallel.procID == (parallel.Nproc - 1):
    Xf=X[-1]
Xi = parallel.bcast(Xi, root=0)
Xf = parallel.bcast(Xf, root=parallel.Nproc - 1)

Welcome to the unintuitive mysteries of parallel race conditions.

@ACamposG
Copy link
Author

ACamposG commented Feb 7, 2019

Thanks a lot John, it worked very nice

@ACamposG ACamposG closed this as completed Feb 7, 2019
@guyer
Copy link
Member

guyer commented Feb 7, 2019

Happy to help

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

No branches or pull requests

2 participants