-
Notifications
You must be signed in to change notification settings - Fork 229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
making sure -DFORCE VECTORIZATION always works fine in SPECFEM3D_Cartesian using the CONTIGUOUS Fortran2008 statement #81
Comments
This only applies to SPECFEM3D_Cartesian; SPECFEM3D_GLOBE is fine (because it uses static arrays in the solver), and there is no FORCE VECTORIZATION in SPECFEM2D, which is thus fine as well. |
The solution would indeed be to use the "CONTIGUOUS" option of Fortran2008, once it is supported by all compilers we routinely use. "CONTIGUOUS Statement and Attribute: Specifies that the target of a pointer or an assumed-sized array is contiguous. The CONTIGUOUS attribute can be specified in a type declaration statement or an CONTIGUOUS statement, and takes one of the following forms: Type Declaration Statement: type, [att-ls,] CONTIGUOUS [, att-ls] :: object [, object] ... Statement: CONTIGUOUS [::] object [, object] ... type Is a data type specifier. att-ls Is an optional list of attribute specifiers. object Is an assumed-shape array or an array pointer. This attribute explicitly indicates that an assumed-shape array is contiguous or that a pointer will only be associated with a contiguous object. An entity can be contiguous even if CONTIGUOUS is not specified. An object is contiguous if it is one of the following:
An object is not contiguous if it is an array subobject, and all of the following are true:
The CONTIGUOUS attribute can make it easier to enable optimizations that rely on the memory layout of an object occupying a contiguous block of memory. The following examples show valid CONTIGUOUS statements: REAL, CONTIGUOUS, DIMENSION(:,:) :: A REAL, POINTER, CONTIGUOUS :: MY_POINTER(:) " (end of citation from https://software.intel.com/sites/products/documentation/doclib/stdxe/2013/composerxe/compiler/fortran-mac/GUID-1C133644-3883-4146-A6BB-1B948B29EDC7.htm ) |
To be safe I have turned -DFORCE VECTORIZATION off by default. |
We could probably just get rid of FORCE_VECTORIZATION support in the code, since modern compilers can do that automatically if the loops are well written. However, since there is currently full support for FORCE_VECTORIZATION in acoustic (fluid) elements, it could turn out to be useful in its current state in the case of mostly acoustic simulations (e.g. in ocean acoustics). |
with PR #310, FORCE_VECTORIZATION is implemented in both fluid and elastic domains. it will again be used by default configuration since it improves code performance. if we still encounter discrepancies between solutions on different systems then we'll turn it off again in the configuration scripts. |
It seems Daniel @danielpeter got rid of FORCE_VECTORIZATION; good idea; thus closing this issue. |
What are the computer system specification need to run the SPECFEM3D. |
The bug below is probably not fixed yet, but we should check with Daniel Peter because he worked on this a bit in August 2013:
The vectorized version of the code (which is compiled when flag -DFORCE VECTORIZATION is used in flags.guess) can fail on some machines because it replaces multiple indices such as (i,j,k) with a 1D version (ijk,1,1). This works fine only if the array is contiguous in memory. This is always the case for static arrays (as used for instance in SPECFEM3D_GLOBE) but the Fortran norm says that it is NOT necessarily the case when dynamic memory allocation is used. Many compilers will use a continuous memory chunk, but some will not and then the vectorized code of FORCE VECTORIZATION will fail.
In Fortran 2008 this is easy to fix by using the "CONTIGUOUS" option in the call to "allocate()", but some compilers may not support it yet. (many compilers still use F95 or F2003, and only parts of F2008).
Another (less elegant) option would be to allocate a 1D array in the allocate statement in the main program, use it in subroutine calls, and then declare and use the arrays as 3D inside all the routines.
The text was updated successfully, but these errors were encountered: