In contrast to what I told in the course it is not trivially possible to map only a part of an array, i.e. a slice, to the target device by setting a lower bound different to 0 in the mapping clause.

To do this correctly, first memory on the device has to be allocated through a runtime function, e.g. omp_target_alloc.  This memory then has to be associated with the slice of the array through omp_target_associate_ptr.  Only then this slice of the array can appear in a map clause. 

Previously associated memory must be disassociated with omp_target_disassociate_ptr and can then be free with omp_target_free.

A detailed example can be found in OpenMP Application Programming Interface -- Examples, V5.2 (https://www.openmp.org/wp-content/uploads/openmp-examples-5.2.1.pdf) under "6.17.4 Device and Host Memory Association".

Last modified: Wednesday, 29 March 2023, 11:51 AM