In the context of MPI with derived data types, I was told to be careful when using the bind(C)
construct, since it blocks certain compiler optimizations. Consider this (a rather unlikely example):
type, bind(C) :: myType integer(2) :: a complex :: z integer(2) :: b end type myType
Without the bind(C)
operator, the compiler is likely to change the order of the structure and group two integers for better alignment. Especially for large structures and when trying to use the auto-vector, this will be useful.
With bind(C)
this rearrangement is not possible (in order to remain compatible with C
, where the compiler probably won't optimize like that). This will lead either to a large memory consumption (three words instead of two) if all elements are word aligned or have lost alignment. (At least that's what they told me.)
Until recently, I had never mixed C and Fortran, and I had never used derived types for MPI exchange. In the near future I am going to study programming in a mixed language, and these problems seem to be important.
So my question is twofold:
bind(C)
: Does this inconsistency play a role in real-world applications? Has anyone experienced performance / optimization issues here?iso_c_binding
: Are there additional errors when (optional) using the iso_c_binding
module? What restrictions are imposed on the code and which optimizations are disabled?
source share