ecmwf-ifs / field_api

Apache License 2.0
3 stars 8 forks source link

Control data synchronization of field wrappers when device data is created #47

Closed pmarguinaud closed 4 months ago

pmarguinaud commented 4 months ago

The following code :

REAL(KIND=JPRB) :: ZZ (NPROMA,NFLEVG,NGPBLKS)
REAL(KIND=JPRB) :: ZP (:,:,:)
CLASS (FIELD_3RB), POINTER :: YLF

CALL FIELD_NEW (YLF, DATA=ZZ)

! Transfer H -> D
ZP => GET_DEVICE_DATA_RDONLY (YLF)

would trigger a transfer, even if ZZ is not initialized.

This PR fixes this issue, introducing the INITIALIZED argument of the FIELD_NEW constructor interface :

REAL(KIND=JPRB) :: ZZ (NPROMA,NFLEVG,NGPBLKS)
REAL(KIND=JPRB) :: ZP (:,:,:)
CLASS (FIELD_3RB), POINTER :: YLF

CALL FIELD_NEW (YLF, DATA=ZZ, INITIALIZED=.FALSE.)

! No transfer H -> D
ZP => GET_DEVICE_DATA_RDONLY (YLF)
pmarguinaud commented 4 months ago

Thank you very much for pointing this out. I have followed your advice; the changes are now minimal, and the code looks much simpler.