Morpho-lang / Morpho-lang/morpho
[Bug] Modifying global variables inside integrands of Functionals segfaults when run in parallel
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 153
- Forks
- 22
- Avg merge
- 9d 10h
- Merged PRs (30d)
- 1
Description
The fix for this is already planned, as mentioned in #259, but I am documenting it here as an open issue for posterity.
Describe the bug
An integrand function of, say, an AreaIntegral, is not allowed to modify state (see #259). This results in a Segmentation Fault if run in multithreaded setting.
To Reproduce
Run the following code using morpho6 -w4
import constants
import meshtools
var mb = MeshBuilder()
mb.addvertex([0,0])
mb.addvertex([1,0])
mb.addvertex([0,1])
mb.addface([0,1,2])
var m = mb.build()
var f = Field(m, fn (x,y) Matrix([x,2*y]))
var r
fn integrand(x, n) {
var g = grad(n)
r = []
for (u in g) r.append(u.clone())
return 0
}
var total = AreaIntegral(integrand, f).total(m)
print r[0]
Note that r is defined in the global scope and being modified inside the integrand.
Expected behavior
Some clear error pointing out that the variable r cannot be modified inside the integrand.
Currently, this generates a segmentation fault.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the provided reproducer with morpho6 -w4 and read the related discussion in #259. Trace how the AreaIntegral integrand handles modification of global variable r during multithreaded execution. Done means the segmentation fault is replaced by a clear error explaining that state cannot be modified inside the integrand.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100