Skip to content

Commit 5bb5fac

Browse files
committed
Fix NAG compiler issues in GMAO_Shared
- Fix m_ioutil.F90: Use TRANSFER() intrinsic for type-safe byte swapping in swapI4_ and swapI8_ functions instead of direct type punning - Fix mpi0/mpi0_copy.F90: Implement TRANSFER-based type conversions using BLOCK constructs for all non-INTEGER MPI types (REAL, DOUBLE_PRECISION, LOGICAL, CHARACTER) to satisfy NAG's strict type checking - Fix windfix.F90: Correct array section syntax from scalar notation (e.g., dglo(1,1,l)) to proper array slices (e.g., dglo(:,:,l)) for calls to GETDIV and VELPOT_SP - Update GMAO_mpeu/CMakeLists.txt: Comment out duplicate MISMATCH flags that are now in common_Fortran_flags to avoid compilation errors All changes maintain backwards compatibility with gfortran and other compilers while fixing NAG compiler strict type checking issues.
1 parent 820aa0f commit 5bb5fac

4 files changed

Lines changed: 72 additions & 22 deletions

File tree

GEOS_Shared/windfix.F90

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ subroutine windfix ( ua,va,plea, &
104104
! --------------------------------
105105
if (size(uglo)>1) then
106106
do l=1,size(uglo,3)
107-
call getdiv (uglo(1,1,l),vglo(1,1,l),dpglo(1,1,l),dglo(1,1,l),img,jmg )
107+
call getdiv (uglo(:,:,l),vglo(:,:,l),dpglo(:,:,l),dglo(:,:,l),img,jmg )
108108
enddo
109109
end if
110110

@@ -134,7 +134,7 @@ subroutine windfix ( ua,va,plea, &
134134
! --------------------------------
135135
if (size(dpglo)>1) then
136136
do l=1,size(uglo,3)
137-
call getdiv (uglo(1,1,l),vglo(1,1,l),dpglo(1,1,l),dglo(1,1,l),img,jmg )
137+
call getdiv (uglo(:,:,l),vglo(:,:,l),dpglo(:,:,l),dglo(:,:,l),img,jmg )
138138
enddo
139139
end if
140140

@@ -211,7 +211,7 @@ subroutine windfix ( ua,va,plea, &
211211
! ------------------------------------------------------------
212212
if (size(dpglo)>1) then
213213
do l=1,size(dglo,3)
214-
call VELPOT_SP (dglo(1,1,l),chi,img,jmg)
214+
call VELPOT_SP (dglo(:,:,l),chi,img,jmg)
215215
call gradq (chi, uchi,vchi,img,jmg)
216216
uglo(:,:,l) = uglo(:,:,l) + uchi(:,:)/dpglo(:,:,l)
217217
vglo(:,:,l) = vglo(:,:,l) + vchi(:,:)/dpglo(:,:,l)

GMAO_mpeu/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ file (MAKE_DIRECTORY ${esma_etc}/GMAO_eu)
5757
set_source_files_properties (m_FileResolv.f90 PROPERTIES COMPILE_FLAGS ${PP})
5858

5959
# NAG notices if the same procedure is called with varying types in the absence
60-
# of an explicit interface.
61-
target_compile_options (${this} PRIVATE $<$<COMPILE_LANGUAGE:Fortran>:${MISMATCH}>)
62-
target_compile_options (GMAO_eu PRIVATE $<$<COMPILE_LANGUAGE:Fortran>:${MISMATCH}>)
60+
# of an explicit interface. The MISMATCH flag is now in common_Fortran_flags.
61+
# target_compile_options (${this} PRIVATE $<$<COMPILE_LANGUAGE:Fortran>:${MISMATCH}>)
62+
# target_compile_options (GMAO_eu PRIVATE $<$<COMPILE_LANGUAGE:Fortran>:${MISMATCH}>)
6363

6464
file (COPY assert.H DESTINATION ${include_${this}})
6565
file (COPY assert.H DESTINATION ${esma_include}/GMAO_eu)

GMAO_mpeu/m_ioutil.F90

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -497,11 +497,12 @@ function swapI4_(ibuf)
497497
!EOP ___________________________________________________________________
498498

499499
character(len=*),parameter :: myname_=myname//'::swapI4_'
500+
character(len=1),dimension(4*size(ibuf)) :: cbuf_in, cbuf_out
500501

501-
! TRANSFER() should be used. The current implementation may be
502-
! not fully portable.
503-
504-
call ioutil_byteswap_(size(ibuf),4,ibuf,swapI4_)
502+
! Use TRANSFER() for proper type conversion (NAG-safe)
503+
cbuf_in = transfer(ibuf, cbuf_in)
504+
call ioutil_byteswap_(size(ibuf),4,cbuf_in,cbuf_out)
505+
swapI4_ = transfer(cbuf_out, swapI4_)
505506

506507
end function swapI4_
507508

@@ -527,11 +528,12 @@ function swapI8_(ibuf)
527528
!EOP ___________________________________________________________________
528529

529530
character(len=*),parameter :: myname_=myname//'::swapI8_'
531+
character(len=1),dimension(8*size(ibuf)) :: cbuf_in, cbuf_out
530532

531-
! TRANSFER() should be used. The current implementation may be
532-
! not fully portable.
533-
534-
call ioutil_byteswap_(size(ibuf),8,ibuf,swapI8_)
533+
! Use TRANSFER() for proper type conversion (NAG-safe)
534+
cbuf_in = transfer(ibuf, cbuf_in)
535+
call ioutil_byteswap_(size(ibuf),8,cbuf_in,cbuf_out)
536+
swapI8_ = transfer(cbuf_out, swapI8_)
535537

536538
end function swapI8_
537539
end module m_ioutil

GMAO_mpeu/mpi0/mpi0_copy.F90

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,25 +42,73 @@ subroutine mpi0_copy(sbuf,scount,stype,rbuf,rcount,rtype,ier)
4242
if( stype==MPI_INTEGER ) then
4343
call copy_INTEGER(sbuf,rbuf,scount)
4444
elseif( stype==MPI_REAL ) then
45-
call copy_REAL(sbuf,rbuf,scount)
45+
! Use TRANSFER for type safety (NAG-compatible)
46+
block
47+
real,dimension(scount) :: sbuf_real, rbuf_real
48+
sbuf_real = transfer(sbuf(1:scount), sbuf_real)
49+
call copy_REAL(sbuf_real,rbuf_real,scount)
50+
rbuf(1:scount) = transfer(rbuf_real, rbuf(1:scount))
51+
end block
4652
elseif( stype==MPI_DOUBLE_PRECISION ) then
47-
call copy_DOUBLE_PRECISION(sbuf,rbuf,scount)
53+
! Use TRANSFER for type safety (NAG-compatible)
54+
block
55+
double precision,dimension(scount) :: sbuf_dbl, rbuf_dbl
56+
sbuf_dbl = transfer(sbuf(1:scount), sbuf_dbl)
57+
call copy_DOUBLE_PRECISION(sbuf_dbl,rbuf_dbl,scount)
58+
rbuf(1:scount) = transfer(rbuf_dbl, rbuf(1:scount))
59+
end block
4860
elseif( stype==MPI_LOGICAL ) then
49-
call copy_LOGICAL(sbuf,rbuf,scount)
61+
! Use TRANSFER for type safety (NAG-compatible)
62+
block
63+
logical,dimension(scount) :: sbuf_log, rbuf_log
64+
sbuf_log = transfer(sbuf(1:scount), sbuf_log)
65+
call copy_LOGICAL(sbuf_log,rbuf_log,scount)
66+
rbuf(1:scount) = transfer(rbuf_log, rbuf(1:scount))
67+
end block
5068
elseif( stype==MPI_CHARACTER ) then
51-
call copy_CHARACTER(sbuf,rbuf,scount)
69+
! Use TRANSFER for type safety (NAG-compatible)
70+
block
71+
character,dimension(scount) :: sbuf_char, rbuf_char
72+
sbuf_char = transfer(sbuf(1:scount), sbuf_char)
73+
call copy_CHARACTER(sbuf_char,rbuf_char,scount)
74+
rbuf(1:scount) = transfer(rbuf_char, rbuf(1:scount))
75+
end block
5276
elseif( stype==MPI_INTEGER4 ) then
5377
call copy_INTEGER4(sbuf,rbuf,scount)
5478
elseif( stype==MPI_REAL4 ) then
55-
call copy_REAL4(sbuf,rbuf,scount)
79+
! Use TRANSFER for type safety (NAG-compatible)
80+
block
81+
real,dimension(scount) :: sbuf_r4, rbuf_r4
82+
sbuf_r4 = transfer(sbuf(1:scount), sbuf_r4)
83+
call copy_REAL4(sbuf_r4,rbuf_r4,scount)
84+
rbuf(1:scount) = transfer(rbuf_r4, rbuf(1:scount))
85+
end block
5686
elseif( stype==MPI_REAL8 ) then
57-
call copy_REAL8(sbuf,rbuf,scount)
87+
! Use TRANSFER for type safety (NAG-compatible)
88+
block
89+
double precision,dimension(scount) :: sbuf_r8, rbuf_r8
90+
sbuf_r8 = transfer(sbuf(1:scount), sbuf_r8)
91+
call copy_REAL8(sbuf_r8,rbuf_r8,scount)
92+
rbuf(1:scount) = transfer(rbuf_r8, rbuf(1:scount))
93+
end block
5894
elseif( stype==MPI_2INTEGER ) then
5995
call copy_INTEGER(sbuf,rbuf,2*scount)
6096
elseif( stype==MPI_2REAL ) then
61-
call copy_REAL(sbuf,rbuf,2*scount)
97+
! Use TRANSFER for type safety (NAG-compatible)
98+
block
99+
real,dimension(2*scount) :: sbuf_real, rbuf_real
100+
sbuf_real = transfer(sbuf(1:2*scount), sbuf_real)
101+
call copy_REAL(sbuf_real,rbuf_real,2*scount)
102+
rbuf(1:2*scount) = transfer(rbuf_real, rbuf(1:2*scount))
103+
end block
62104
elseif( stype==MPI_2DOUBLE_PRECISION ) then
63-
call copy_DOUBLE_PRECISION(sbuf,rbuf,2*scount)
105+
! Use TRANSFER for type safety (NAG-compatible)
106+
block
107+
double precision,dimension(2*scount) :: sbuf_dbl, rbuf_dbl
108+
sbuf_dbl = transfer(sbuf(1:2*scount), sbuf_dbl)
109+
call copy_DOUBLE_PRECISION(sbuf_dbl,rbuf_dbl,2*scount)
110+
rbuf(1:2*scount) = transfer(rbuf_dbl, rbuf(1:2*scount))
111+
end block
64112
else
65113
ier=stype
66114
if(stype==0) ier=MPI_UNDEFINED

0 commit comments

Comments
 (0)