Software Archive
Read-only legacy content
17061 Discussions

inout

Jen_B_
Beginner
743 Views

if i do as follows in fortran

...

integer,allocatable::a(:)

...

allocate(a(n))

...

!dir$ offload target(mic) inout(a)

!$omp parallel do...

inside the do loop a is being passed to subroutines and assigned values. is it ok to put a inside inout as above? or is there anything still needed? Thanks!

0 Kudos
6 Replies
Kevin_D_Intel
Employee
743 Views

Looks like that should work. I believe the array size is known at run-time and included in the array descriptor passed with the offload so length(n) modifier is not needed for the code you outlined. If you do not need the initial values of A from the host then you could avoid the data transfer of those initial values using OUT vs. INOUT.

0 Kudos
Jen_B_
Beginner
743 Views

Thanks! Also, what happens internally regarding the alloc_if/free_if. As far as I understand default for those is true, so in my case space for "a" allocated on coprocessor before copying the data from host to coprocessor, then the data copied into data space, then the final results of "a" are copied from coprocessor to host space of "a", and at the end coprocessor deallocates space allocated for "a" on coprocessor. Am I right?

0 Kudos
Kevin_D_Intel
Employee
743 Views

Here's the detail I could not recall earlier and just found in the Fortran UG under the LENGTH ( element-count-expr ) on the OFFLOAD topic.

A Fortran array variable can be one of four major types: explicit-shape, assumed-shape, deferred-shape and assumed-size. The runtime descriptor for the first three types makes that array variable's size known at compile time or at runtime.
...
By default, the compiler copies explicit-shape, assumed-shape and deferred-shape arrays in their entirety. They do not need an element-count-expr. However, you can use an optional element-count-expr to specify the total number of elements to copy, which limits the number of elements copied back and forth in the last dimension of the array.

 

0 Kudos
Kevin_D_Intel
Employee
743 Views

Yes, you are correct about the behavior of the alloc_if/free_if.

0 Kudos
Jen_B_
Beginner
743 Views

Thanks a lot!

0 Kudos
Kevin_D_Intel
Employee
743 Views

You're welcome.

0 Kudos
Reply