OpenMP foreach + multiple list iterators

84 views
Skip to first unread message

Vrionis Yiannis

unread,
Jan 9, 2023, 9:29:42 AM1/9/23
to basilisk-fr

Hello everyone!

I think there might be a bug when combining list iterators with foreach loops when OpenMP is enabled (Basilisk - Basilisk C).

I am attaching a MWE, which shows that if the list iterator loop is nested, the variable is not correctly copied, whereas if the foreach() loop is nested it is correctly performs the nested loop. The purpose of the MWE is to update the values of the scalar holding the old values (oldVars) with the new ones (curVars).

I have also attached the outputs for both cases.
Compilation is done via
qcc test.c -fopenmp -lm

Thank you!

out1_withError
test.c
out0_ok

Stephane Popinet

unread,
Jan 9, 2023, 10:20:17 AM1/9/23
to basil...@googlegroups.com
Hi Vrionis,

There is indeed a bug in your code. You should be able to find it by
reading carefully the _documentation_:

http://basilisk.fr/Basilisk%20C#parallel-programming

especially the last two paragraphs...

Please post the solution when you have found it and we can discuss
further (there is a further minor bug which is worth pointing out).

Stephane

Vrionis Yiannis

unread,
Jan 9, 2023, 11:36:06 AM1/9/23
to basilisk-fr

Dear Stephane,

Thanks for the prompt reply. Excluding serializing the entire loop, defining local scalars solves the discrepancy, i.e.
event update(i< 2; i++) { foreach() { scalar curVar, oldVar; // Local scalars solve the problem for (curVar, oldVar in lc, lo) { oldVar[] = curVar[]; } } fields_stats(); }

For some reason I was thinking curVar and oldVar were scalar fields, but after your comment I realized my mistake.
(Sorry if my reply took some time, I was trying to figure out what the other bug you mentioned was).

Thanks,

Yiannis

Stephane Popinet

unread,
Jan 9, 2023, 12:40:43 PM1/9/23
to basil...@googlegroups.com
Hi Yiannis,

This is indeed the correct explanation and fix.

The "other bug" is indeed a bug in Basilisk, which should not allow this
and fail to compile/run. You can try the same thing with a "double" or
an "int" and you should see that it fails.

So please post a bug report:

http://basilisk.fr/sandbox/bugs/README

Stephane

Vrionis Yiannis

unread,
Jan 9, 2023, 12:56:15 PM1/9/23
to basilisk-fr

Hi Stephane,

I imagine you are referring to a code snippet of this type (?),

event update(i< 2; i++) { double x; foreach() { x = sq(f[]); f[] = x; } fields_stats(); }

I just successfully compiled this. I have the latest basilisk/qcc version.

So, should I add this to the report, as well?

Thanks,
Yiannis

Stephane Popinet

unread,
Jan 11, 2023, 4:29:18 AM1/11/23
to basil...@googlegroups.com
> I just successfully compiled this. I have the latest basilisk/qcc version.
>
> So, should I add this to the report, as well?

You should also try to run it: some errors are detected at runtime.

But, yes, it is useful in your bug report to explore which cases do or
do not report an error.

cheers,

Stephane

Reply all
Reply to author
Forward
0 new messages