introduced racing condition breaker for the case of multithreaded CPFEM init.

This commit is contained in:
Philip Eisenlohr 2010-02-02 15:00:08 +00:00
parent 101d4c6bb4
commit f186c83068
1 changed files with 30 additions and 17 deletions

View File

@ -16,6 +16,7 @@ real(pReal), dimension (:,:,:,:), allocatable :: CPFEM_dcsdE
real(pReal), dimension (:,:,:,:), allocatable :: CPFEM_dcsdE_knownGood ! known good tangent
logical :: CPFEM_init_done = .false., & ! remember whether init has been done already
CPFEM_init_inProgress = .false., & ! remember whether first IP is currently performing init
CPFEM_calc_done = .false. ! remember whether first IP has already calced the results
@ -169,6 +170,13 @@ subroutine CPFEM_general(mode, ffn, ffn1, Temperature, dt, element, IP, cauchySt
! initialization step (three dimensional stress state check missing?)
if (.not. CPFEM_init_done) then
call random_number(rnd)
do i=1,int(256.0*rnd)
n = n+1_pInt ! wasting random amount of time...
enddo ! ...to break potential race in multithreading
n = n+1_pInt
if (.not. CPFEM_init_inProgress) then ! yes my thread won!
CPFEM_init_inProgress = .true.
call prec_init()
call IO_init()
call numerics_init()
@ -184,6 +192,11 @@ subroutine CPFEM_general(mode, ffn, ffn1, Temperature, dt, element, IP, cauchySt
call CPFEM_init()
call mpie_cpfem_init()
CPFEM_init_done = .true.
CPFEM_init_inProgress = .false.
else ! loser, loser...
do while (CPFEM_init_inProgress)
end do
endif
endif
cp_en = mesh_FEasCP('elem',element)