Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

Pointers and parallel regions

OP1
New Contributor III
553 Views

Let's assume that I have initialized a pointer P and its associated target T outside a parallel region. Then, from within a parallel region, I call a subroutine SUB(P), having declared P as shared in the parallel region directives.

Is it correct to assume thatthe threads calling SUB will all have proper access to the values of T?

Thanks in advance,

Olivier

0 Kudos
2 Replies
jimdempseyatthecove
Honored Contributor III
553 Views

Olivier,

The threads inside SUB will have access to values of T. However, as to having "proper access" it is up to you.

Example of improper access

T%value = T%value + incriment

Example of proper access

!$OMP ATOMIC
T%value = T%value + incriment

Reading is generally safe (except for sequencing issues)
Writing is generally safe (except for sequencing issues)
Updating is generally unsafe without atomic or critical section.

When coding SUB you have to be aware that values within the shared object can change at unpredictable times and take proper precautions.

Jim Dempsey

0 Kudos
OP1
New Contributor III
553 Views

Thanks Jim - I was concerned that since each thread makes a duplicate of the code, the address this pointer refers to would be *local* to each thread.

Olivier

0 Kudos
Reply