Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28867 Discussions

Incorrect answer with do concurrent reduce

everythingfunctional
New Contributor I
1,097 Views

I would expect the two attached programs to give identical results, but they do not. Both are compiled with ifx, using the -qopenmp option for the do concurrent case. I realize that the do concurrent version does not initialize c to 0, but the standard says:

 

>  Before execution of the iterations begins, the construct entity is assigned an initial value corresponding to its reduce-operation as specified in Table 11.1.

 

I'll also note that an equivalent openmp version does get the correct answer.

0 Kudos
1 Solution
Barbara_P_Intel
Employee
995 Views

The array C has never been initialized and should be initialized independent of the DO CONCURRENT.

Inside the DO CONCURRENT, there are construct entities c that have the same type, rank, shape as c outside.

The construct entities are initialized to zero at the beginning of each iteration. At the end of the construct, the value of each construct entity is combined with the outside variable c. So,  c1, c2, … cn are the construct entities for the n iterations of the loop.

After the loop c1, c2, … cn are combined with c the outside variable as if

   c = c + c1 + c2 + … + cn

I set c=0.0 before the DO CONCURRENT construct and get the same answer as the serial and OpenMP versions.

GIGO... garbage in, garbage out.

See 11.1.7.5 Additional semantics of DO CONCURRENT constructs paragraph 5:

              If a variable has REDUCE locality, on termination of the DO CONCURRENT construct the outside variable 

is updated by combining it with the values the construct entity had at completion of each iteration, using the

reduce-operator. The processor may combine the values in any order.

 

 

 

View solution in original post

0 Kudos
7 Replies
Barbara_P_Intel
Employee
1,035 Views

I'll take a look at this.

Which version of ifx are you using?

Please tell me the compiler options you are using other than -qopenmp.

Thank you!

 

 

0 Kudos
Barbara_P_Intel
Employee
1,026 Views

FYI... You should use wall clock time to time parallel codes. system_clock gathers the CPU time for all threads.


0 Kudos
JohnNichols
Valued Contributor III
1,016 Views

As of 2035 the wall clock will no longer include leap seconds as the cost to industry is high.  We are now divorced from the Sun God as the earth slows and a year is not a real year, whatever that means. 

 

0 Kudos
everythingfunctional
New Contributor I
1,005 Views

Hi Barbara, I'm using ifx 2024.0.2 20231213, with only the -qopenmp option.

 

Thanks for the heads up about timing. Is the suggestion to use CPU_TIME? or DATE_AND_TIME?

0 Kudos
Barbara_P_Intel
Employee
1,002 Views

These are the routines I use for timing threaded applications.

 

0 Kudos
Barbara_P_Intel
Employee
996 Views

The array C has never been initialized and should be initialized independent of the DO CONCURRENT.

Inside the DO CONCURRENT, there are construct entities c that have the same type, rank, shape as c outside.

The construct entities are initialized to zero at the beginning of each iteration. At the end of the construct, the value of each construct entity is combined with the outside variable c. So,  c1, c2, … cn are the construct entities for the n iterations of the loop.

After the loop c1, c2, … cn are combined with c the outside variable as if

   c = c + c1 + c2 + … + cn

I set c=0.0 before the DO CONCURRENT construct and get the same answer as the serial and OpenMP versions.

GIGO... garbage in, garbage out.

See 11.1.7.5 Additional semantics of DO CONCURRENT constructs paragraph 5:

              If a variable has REDUCE locality, on termination of the DO CONCURRENT construct the outside variable 

is updated by combining it with the values the construct entity had at completion of each iteration, using the

reduce-operator. The processor may combine the values in any order.

 

 

 

0 Kudos
everythingfunctional
New Contributor I
990 Views

:facepalm: "update" not "assign"

 

> If a variable has REDUCE locality, on termination of the DO CONCURRENT construct the outside variable is updated by combining it with the values the construct entity had at completion of each iteration, using the reduce-operation. 

 

Sorry for misunderstanding.

0 Kudos
Reply