Skip to content

Commit 7490c8c

Browse files
committed
adds allocation checks
1 parent e0010a5 commit 7490c8c

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

src/specfem2D/prepare_gpu.f90

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ subroutine init_host_to_dev_variable()
362362
! local parameters
363363
integer :: i_spec_free,ipoint1D,i,j,ispec,i_source,i_source_local,ispec_PML,ielem
364364
integer :: ispec_acoustic,ispec_elastic,iedge_acoustic,iedge_elastic
365-
integer :: inum
365+
integer :: inum,ier
366366
real(kind=CUSTOM_REAL) :: zxi,xgamma,jacobian1D
367367
real(kind=CUSTOM_REAL) :: xxi,zgamma
368368
real(kind=CUSTOM_REAL), dimension(:,:,:), allocatable :: abs_normalized_temp
@@ -396,29 +396,34 @@ subroutine init_host_to_dev_variable()
396396
! spec_to_PML_GPU(ispec) \in [NSPEC_PML_X + 1, NSPEC_PML_X + NSPEC_PML_Z] indicates the element is in the region CPML_Z_ONLY
397397
! spec_to_PML_GPU(ispec) > NSPEC_PML_X + NSPEC_PML_Z indicates the element is in the region CPML_XZ
398398
! Finally, spec_to_PML_GPU(ispec) = ielem, where ielem the local number of the element in the PML
399-
allocate(spec_to_PML_GPU(nspec))
399+
allocate(spec_to_PML_GPU(nspec),stat=ier)
400+
if (ier /= 0) stop 'Error allocating spec_to_PML_GPU array'
400401
spec_to_PML_GPU(:) = 0
402+
401403
nspec_PML_X = 0
402404
do ispec = 1,nspec
403405
if (region_CPML(ispec) == CPML_X_ONLY ) then
404406
nspec_PML_X = nspec_PML_X+1
405407
spec_to_PML_GPU(ispec) = nspec_PML_X
406408
endif
407409
enddo
410+
408411
nspec_PML_Z = 0
409412
do ispec = 1,nspec
410413
if (region_CPML(ispec) == CPML_Z_ONLY ) then
411414
nspec_PML_Z = nspec_PML_Z+1
412415
spec_to_PML_GPU(ispec) = nspec_PML_X + nspec_PML_Z
413416
endif
414417
enddo
418+
415419
nspec_PML_XZ = 0
416420
do ispec = 1,nspec
417421
if (region_CPML(ispec) == CPML_XZ ) then
418422
nspec_PML_XZ = nspec_PML_XZ+1
419423
spec_to_PML_GPU(ispec) = nspec_PML_X + nspec_PML_Z + nspec_PML_XZ
420424
endif
421425
enddo
426+
422427
! user output
423428
if (myrank == 0) then
424429
write(IMAIN,*) ' number of PML elements in this process slice = ',nspec_PML
@@ -437,17 +442,24 @@ subroutine init_host_to_dev_variable()
437442

438443
! EB EB : We reorganize the arrays abs_normalized and abs_normalized2 that
439444
! don't have the correct dimension and new local element numbering
440-
allocate(abs_normalized_temp(NGLLX,NGLLZ,NSPEC))
445+
allocate(abs_normalized_temp(NGLLX,NGLLZ,NSPEC),stat=ier)
446+
if (ier /= 0) stop 'Error allocating abs_normalized_temp array'
441447
abs_normalized_temp(:,:,:) = abs_normalized(:,:,:)
442448
deallocate(abs_normalized)
443-
allocate(abs_normalized(NGLLX,NGLLZ,NSPEC_PML))
449+
450+
allocate(abs_normalized(NGLLX,NGLLZ,NSPEC_PML),stat=ier)
451+
if (ier /= 0) stop 'Error allocating abs_normalized array'
452+
abs_normalized(:,:,:) = 0.0_CUSTOM_REAL
444453
do ispec = 1,nspec
445454
if (spec_to_PML_GPU(ispec) > 0) abs_normalized(:,:,spec_to_PML_GPU(ispec)) = abs_normalized_temp(:,:,ispec)
446455
enddo
447456
deallocate(abs_normalized_temp)
448457

449-
allocate(alphax_store_GPU(NGLLX,NGLLZ,NSPEC_PML_XZ),alphaz_store_GPU(NGLLX,NGLLZ,NSPEC_PML_XZ), &
450-
betax_store_GPU(NGLLX,NGLLZ,NSPEC_PML_XZ),betaz_store_GPU(NGLLX,NGLLZ,NSPEC_PML_XZ))
458+
allocate(alphax_store_GPU(NGLLX,NGLLZ,NSPEC_PML_XZ), &
459+
alphaz_store_GPU(NGLLX,NGLLZ,NSPEC_PML_XZ), &
460+
betax_store_GPU(NGLLX,NGLLZ,NSPEC_PML_XZ), &
461+
betaz_store_GPU(NGLLX,NGLLZ,NSPEC_PML_XZ),stat=ier)
462+
if (ier /= 0) stop 'Error allocating alphax_store_GPU,.. arrays'
451463
alphax_store_GPU(:,:,:) = 0.0_CUSTOM_REAL
452464
alphaz_store_GPU(:,:,:) = 0.0_CUSTOM_REAL
453465
betax_store_GPU(:,:,:) = 0.0_CUSTOM_REAL

0 commit comments

Comments
 (0)