Skip to content

Commit

Permalink
nullifications of several variables, ensured constant encoding transf…
Browse files Browse the repository at this point in the history
…er type

* Several pointer data-containers did not have nullified variables
  which could be an issue.
  All needed data-containers should now use nullified variables.

* The transfer data type is now a constant variable instead of the
  non-allocated variable from the data-container.
  This should ensure intel compilers.
  • Loading branch information
zerothi committed Jan 23, 2015
1 parent c6e77b5 commit 2f28d4b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
4 changes: 2 additions & 2 deletions var.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ for v in ${vars[@]} ; do
for d in `seq 0 $(var_N $v)` ; do
_psnl "if ( this%t == '$v$d' ) then"
_psnl "p$v${d}_1%p = p$v${d}_2%p"
_psnl "allocate(this%enc(size(transfer(p$v${d}_1, this%enc))))"
_psnl "this%enc = transfer(p$v${d}_1, this%enc)"
_psnl "allocate(this%enc(size(transfer(p$v${d}_1, local_enc_type))))"
_psnl "this%enc = transfer(p$v${d}_1, local_enc_type)"
[ $d -lt $(var_N $v) ] && _ps "else"
done
_psnl "endif"
Expand Down
25 changes: 12 additions & 13 deletions var_funcs_inc.inc
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,19 @@ subroutine ROUTINE(assign_set,VAR)(this,rhs,dealloc)
! ASSIGNMENT in fortran is per default destructive
ldealloc = .true.
if(present(dealloc))ldealloc = dealloc
if (.not. ldealloc) then
! if we do not deallocate, nullify
if (ldealloc) then
call delete(this)
else
call nullify(this)
this%t = STR(VAR) ! set type
ALLOC(p%p,rhs) ! allocate space
p%p = rhs ! copy data over
allocate(this%enc(size(transfer(p, this%enc)))) ! allocate encoding
this%enc = transfer(p, this%enc) ! transfer pointer type to the encoding
return
end if
! With pointer transfer we need to deallocate
! else bounds might change...
call delete(this)
this%t = STR(VAR)
nullify(p%p)
ALLOC(p%p,rhs) ! allocate space
p%p = rhs ! copy data over
allocate(this%enc(size(transfer(p, this%enc)))) ! allocate encoding
this%enc = transfer(p, this%enc) ! transfer pointer type to the encoding
allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
this%enc = transfer(p, local_enc_type) ! transfer pointer type to the encoding
end subroutine ROUTINE(assign_set,VAR)

subroutine ROUTINE(assign_get,VAR)(lhs,this,success)
Expand All @@ -40,6 +35,7 @@ subroutine ROUTINE(assign_get,VAR)(lhs,this,success)
VAR_TYPE, pointer DIMS :: p
end type
type(pt) :: p
nullify(p%p)
lsuccess = this%t == STR(VAR)
#if DIM > 0
if (lsuccess) then
Expand Down Expand Up @@ -76,6 +72,7 @@ subroutine ROUTINE(associate_get,VAR)(lhs,this,dealloc,success)
nullify(lhs)
end if
if (.not. lsuccess ) return
nullify(p%p)
p = transfer(this%enc,p) ! retrieve pointer encoding
lhs => p%p
end subroutine ROUTINE(associate_get,VAR)
Expand All @@ -98,8 +95,8 @@ subroutine ROUTINE(associate_set,VAR)(this,rhs,dealloc)
end if
this%t = STR(VAR)
p%p => rhs
allocate(this%enc(size(transfer(p, this%enc)))) ! allocate encoding
this%enc = transfer(p, this%enc) ! transfer pointer type to the encoding
allocate(this%enc(size(transfer(p, local_enc_type)))) ! allocate encoding
this%enc = transfer(p, local_enc_type) ! transfer pointer type to the encoding
end subroutine ROUTINE(associate_set,VAR)

pure function ROUTINE(associatd_l,VAR)(lhs,this) result(ret)
Expand All @@ -112,6 +109,7 @@ pure function ROUTINE(associatd_l,VAR)(lhs,this) result(ret)
type(pt) :: p
ret = this%t == STR(VAR)
if (ret) then
nullify(p%p)
p = transfer(this%enc,p)
ret = associated(lhs,p%p)
endif
Expand All @@ -126,6 +124,7 @@ pure function ROUTINE(associatd_r,VAR)(this,rhs) result(ret)
type(pt) :: p
ret = this%t == STR(VAR)
if (ret) then
nullify(p%p)
p = transfer(this%enc,p)
ret = associated(p%p,rhs)
endif
Expand Down
4 changes: 4 additions & 0 deletions variable.F90
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ module variable
integer, parameter :: il = selected_int_kind(18)
integer, parameter :: sp = selected_real_kind(p=6)
integer, parameter :: dp = selected_real_kind(p=15)

! To create a constant transfer data-type of the
! pointer methods
character(len=1) :: local_enc_type(1)

type :: var
character(len=2) :: t = ' '
Expand Down

0 comments on commit 2f28d4b

Please sign in to comment.