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

[Bug] Modifying global variables inside integrands of Functionals segfaults when run in parallel #262

Open
joshichaitanya3 opened this issue May 22, 2024 · 0 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@joshichaitanya3
Copy link
Collaborator

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.

@joshichaitanya3 joshichaitanya3 added bug Something isn't working enhancement New feature or request labels May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant