From d65a71210e1050fc5a40d45d16f487dbc5a304b0 Mon Sep 17 00:00:00 2001 From: Salvatore Filippone Date: Wed, 1 May 2019 15:35:00 +0100 Subject: [PATCH] Make sure default coarse size does not overflow for large matrices. --- mlprec/impl/mld_c_hierarchy_bld.f90 | 15 ++++++++++++--- mlprec/impl/mld_d_hierarchy_bld.f90 | 15 ++++++++++++--- mlprec/impl/mld_s_hierarchy_bld.f90 | 15 ++++++++++++--- mlprec/impl/mld_z_hierarchy_bld.f90 | 15 ++++++++++++--- 4 files changed, 48 insertions(+), 12 deletions(-) diff --git a/mlprec/impl/mld_c_hierarchy_bld.f90 b/mlprec/impl/mld_c_hierarchy_bld.f90 index 56c3057c..a16dd024 100644 --- a/mlprec/impl/mld_c_hierarchy_bld.f90 +++ b/mlprec/impl/mld_c_hierarchy_bld.f90 @@ -79,8 +79,9 @@ subroutine mld_c_hierarchy_bld(a,desc_a,prec,info) ! Local Variables integer(psb_ipk_) :: ictxt, me,np - integer(psb_ipk_) :: err,i,k, err_act, iszv, newsz, casize,& - & nplevs, mxplevs, iaggsize + integer(psb_ipk_) :: err,i,k, err_act, iszv, newsz,& + & nplevs, mxplevs + integer(psb_lpk_) :: iaggsize, casize real(psb_spk_) :: mnaggratio, sizeratio, athresh, aomega class(mld_c_base_smoother_type), allocatable :: coarse_sm, base_sm, med_sm, & & base_sm2, med_sm2, coarse_sm2 @@ -196,7 +197,15 @@ subroutine mld_c_hierarchy_bld(a,desc_a,prec,info) casize = max(casize,ione) casize = casize*40_psb_ipk_ call psb_bcast(ictxt,casize) - prec%ag_data%min_coarse_size = casize + if (casize > huge(prec%ag_data%min_coarse_size)) then + ! + ! computed coarse size does not fit in IPK_. + ! This is very unlikely, but make sure to put a positive number + ! + prec%ag_data%min_coarse_size = huge(prec%ag_data%min_coarse_size) + else + prec%ag_data%min_coarse_size = casize + end if end if nplevs = max(itwo,mxplevs) diff --git a/mlprec/impl/mld_d_hierarchy_bld.f90 b/mlprec/impl/mld_d_hierarchy_bld.f90 index 40e8f216..57cbfc05 100644 --- a/mlprec/impl/mld_d_hierarchy_bld.f90 +++ b/mlprec/impl/mld_d_hierarchy_bld.f90 @@ -79,8 +79,9 @@ subroutine mld_d_hierarchy_bld(a,desc_a,prec,info) ! Local Variables integer(psb_ipk_) :: ictxt, me,np - integer(psb_ipk_) :: err,i,k, err_act, iszv, newsz, casize,& - & nplevs, mxplevs, iaggsize + integer(psb_ipk_) :: err,i,k, err_act, iszv, newsz,& + & nplevs, mxplevs + integer(psb_lpk_) :: iaggsize, casize real(psb_dpk_) :: mnaggratio, sizeratio, athresh, aomega class(mld_d_base_smoother_type), allocatable :: coarse_sm, base_sm, med_sm, & & base_sm2, med_sm2, coarse_sm2 @@ -196,7 +197,15 @@ subroutine mld_d_hierarchy_bld(a,desc_a,prec,info) casize = max(casize,ione) casize = casize*40_psb_ipk_ call psb_bcast(ictxt,casize) - prec%ag_data%min_coarse_size = casize + if (casize > huge(prec%ag_data%min_coarse_size)) then + ! + ! computed coarse size does not fit in IPK_. + ! This is very unlikely, but make sure to put a positive number + ! + prec%ag_data%min_coarse_size = huge(prec%ag_data%min_coarse_size) + else + prec%ag_data%min_coarse_size = casize + end if end if nplevs = max(itwo,mxplevs) diff --git a/mlprec/impl/mld_s_hierarchy_bld.f90 b/mlprec/impl/mld_s_hierarchy_bld.f90 index e159b368..f25fc9c5 100644 --- a/mlprec/impl/mld_s_hierarchy_bld.f90 +++ b/mlprec/impl/mld_s_hierarchy_bld.f90 @@ -79,8 +79,9 @@ subroutine mld_s_hierarchy_bld(a,desc_a,prec,info) ! Local Variables integer(psb_ipk_) :: ictxt, me,np - integer(psb_ipk_) :: err,i,k, err_act, iszv, newsz, casize,& - & nplevs, mxplevs, iaggsize + integer(psb_ipk_) :: err,i,k, err_act, iszv, newsz,& + & nplevs, mxplevs + integer(psb_lpk_) :: iaggsize, casize real(psb_spk_) :: mnaggratio, sizeratio, athresh, aomega class(mld_s_base_smoother_type), allocatable :: coarse_sm, base_sm, med_sm, & & base_sm2, med_sm2, coarse_sm2 @@ -196,7 +197,15 @@ subroutine mld_s_hierarchy_bld(a,desc_a,prec,info) casize = max(casize,ione) casize = casize*40_psb_ipk_ call psb_bcast(ictxt,casize) - prec%ag_data%min_coarse_size = casize + if (casize > huge(prec%ag_data%min_coarse_size)) then + ! + ! computed coarse size does not fit in IPK_. + ! This is very unlikely, but make sure to put a positive number + ! + prec%ag_data%min_coarse_size = huge(prec%ag_data%min_coarse_size) + else + prec%ag_data%min_coarse_size = casize + end if end if nplevs = max(itwo,mxplevs) diff --git a/mlprec/impl/mld_z_hierarchy_bld.f90 b/mlprec/impl/mld_z_hierarchy_bld.f90 index c4dcac39..40d0b2ec 100644 --- a/mlprec/impl/mld_z_hierarchy_bld.f90 +++ b/mlprec/impl/mld_z_hierarchy_bld.f90 @@ -79,8 +79,9 @@ subroutine mld_z_hierarchy_bld(a,desc_a,prec,info) ! Local Variables integer(psb_ipk_) :: ictxt, me,np - integer(psb_ipk_) :: err,i,k, err_act, iszv, newsz, casize,& - & nplevs, mxplevs, iaggsize + integer(psb_ipk_) :: err,i,k, err_act, iszv, newsz,& + & nplevs, mxplevs + integer(psb_lpk_) :: iaggsize, casize real(psb_dpk_) :: mnaggratio, sizeratio, athresh, aomega class(mld_z_base_smoother_type), allocatable :: coarse_sm, base_sm, med_sm, & & base_sm2, med_sm2, coarse_sm2 @@ -196,7 +197,15 @@ subroutine mld_z_hierarchy_bld(a,desc_a,prec,info) casize = max(casize,ione) casize = casize*40_psb_ipk_ call psb_bcast(ictxt,casize) - prec%ag_data%min_coarse_size = casize + if (casize > huge(prec%ag_data%min_coarse_size)) then + ! + ! computed coarse size does not fit in IPK_. + ! This is very unlikely, but make sure to put a positive number + ! + prec%ag_data%min_coarse_size = huge(prec%ag_data%min_coarse_size) + else + prec%ag_data%min_coarse_size = casize + end if end if nplevs = max(itwo,mxplevs)