-
-
Notifications
You must be signed in to change notification settings - Fork 410
Update parallelism.md #4072
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
Update parallelism.md #4072
Conversation
The original description is not comprehensive. I add a quote from Julia's doc.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4072 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 43 43
Lines 6203 6203
=========================================
Hits 6203 6203 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Clarify the explanation of race conditions and thread safety.
I made a tweak. Any better? |
"mutate" should be a sharper word than "modify"? describing functions like PS I'm currently very confused about the "name" (variable) in julia, whether they refer to the same object. As that link suggests. I'll figure that out first. |
Clarified the explanation of data races and provided examples of incorrect multi-threading usage with JuMP models.
What about this. I added a much larger description and example |
I think "Read and write type 1 modification is to mutate something type 2 modification is reuse the name and re-bind it to another object type 3 modification
(Any others?) |
Type 1: you're modifying If I can give you some unsolicited advice, your questions on Discourse all stem from the fact there Julia's scoping has some tricky edge cases. So just don't write code like that. Don't do your Type 3 example where |
I think there is some philosophy in there for julia to deem it valid. The unintroduced Using a mutable container is also convincing, I'll rethink that. |
Just because it can be valid doesn't mean that you should use it.
I strongly disagree with this approach. You should explicitly pass the master solution to the subproblem. Don't rely on scope changing. Push first-stage primal solutions to a channel or a vector. Don't rely on scoping rules to change the value of Anyway, we're off-topic for this PR, which was useful and appreciated 😄 |
It indeed appears to be a bit cleaner under the lens of code_warntype function masterˈs_loop_rebinding_version(snap)
while true
# optimize!(master_model)
snap = (x = value(x), z = round(Int, value(z)))
for j = 1:4 # assume 4 blocks
Threads.@spawn subproblemˈs_duty(j, snap)
end
end
end
@code_warntype masterˈs_loop_rebinding_version((x = 3.4, z = 2))
const snap = NamedTuple[(x = 3.4, z = 2)]
function masterˈs_loop_container_version()
while true
# optimize!(master_model)
snap[] = (x = value(x), z = round(Int, value(z)))
for j = 1:4 # assume 4 blocks
Threads.@spawn subproblemˈs_duty(j, snap[])
end
end
end
@code_warntype masterˈs_loop_container_version() |
Share some further thoughts about the issue. https://discourse.julialang.org/t/is-it-defined-behavior-to-modify-iter-while-for-looping-over-it/132477/33?u=waltermadelim Anyway, The async programming with
|
The original description is not comprehensive. I add a quote from Julia's doc.
PS some related discussion https://discourse.julialang.org/t/is-it-defined-behavior-to-modify-iter-while-for-looping-over-it/132477/14?u=waltermadelim