From 86a6ab413a9d3f0fd26cc34e3d0166918fe87105 Mon Sep 17 00:00:00 2001 From: sfilippone Date: Fri, 27 Jun 2025 14:03:46 +0200 Subject: [PATCH] Use less memory in spspmm --- base/serial/impl/psb_c_csr_impl.F90 | 12 ++++++------ base/serial/impl/psb_d_csr_impl.F90 | 12 ++++++------ base/serial/impl/psb_s_csr_impl.F90 | 12 ++++++------ base/serial/impl/psb_z_csr_impl.F90 | 12 ++++++------ 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/base/serial/impl/psb_c_csr_impl.F90 b/base/serial/impl/psb_c_csr_impl.F90 index 9b9090cd..73324073 100644 --- a/base/serial/impl/psb_c_csr_impl.F90 +++ b/base/serial/impl/psb_c_csr_impl.F90 @@ -3693,7 +3693,7 @@ subroutine psb_ccsrspspmm(a,b,c,info) ! Estimate number of nonzeros on output. nza = a%get_nzeros() nzb = b%get_nzeros() - nzc = 2*(nza+nzb) + nzc = max(nint(0.5*(nza+nzb)),ma,mb,na,nb) call c%allocate(ma,nb,nzc) call csr_spspmm(a,b,c,info) @@ -3773,8 +3773,8 @@ contains if (nrc > 0 ) then if ((nzc+nrc)>nze) then nze = max(ma*((nzc+j-1)/j),nzc+2*nrc) - call psb_realloc(nze,c%val,info) - if (info == 0) call psb_realloc(nze,c%ja,info) + call psb_ensure_size(nze,c%val,info) + if (info == 0) call psb_ensure_size(nze,c%ja,info) if (info /= 0) return end if @@ -4238,7 +4238,7 @@ subroutine psb_ccsrspspmm(a,b,c,info) ! Estimate number of nonzeros on output. nza = a%get_nzeros() nzb = b%get_nzeros() - nzc = 2*(nza+nzb) + nzc = max(nint(0.5*(nza+nzb)),ma,mb,na,nb) call c%allocate(ma,nb,nzc) call csr_spspmm(a,b,c,info) @@ -4303,8 +4303,8 @@ contains if (nrc > 0 ) then if ((nzc+nrc)>nze) then nze = max(ma*((nzc+j-1)/j),nzc+2*nrc) - call psb_realloc(nze,c%val,info) - if (info == 0) call psb_realloc(nze,c%ja,info) + call psb_ensure_size(nze,c%val,info) + if (info == 0) call psb_ensure_size(nze,c%ja,info) if (info /= 0) return end if diff --git a/base/serial/impl/psb_d_csr_impl.F90 b/base/serial/impl/psb_d_csr_impl.F90 index b689d189..7d8f477b 100644 --- a/base/serial/impl/psb_d_csr_impl.F90 +++ b/base/serial/impl/psb_d_csr_impl.F90 @@ -3693,7 +3693,7 @@ subroutine psb_dcsrspspmm(a,b,c,info) ! Estimate number of nonzeros on output. nza = a%get_nzeros() nzb = b%get_nzeros() - nzc = 2*(nza+nzb) + nzc = max(nint(0.5*(nza+nzb)),ma,mb,na,nb) call c%allocate(ma,nb,nzc) call csr_spspmm(a,b,c,info) @@ -3773,8 +3773,8 @@ contains if (nrc > 0 ) then if ((nzc+nrc)>nze) then nze = max(ma*((nzc+j-1)/j),nzc+2*nrc) - call psb_realloc(nze,c%val,info) - if (info == 0) call psb_realloc(nze,c%ja,info) + call psb_ensure_size(nze,c%val,info) + if (info == 0) call psb_ensure_size(nze,c%ja,info) if (info /= 0) return end if @@ -4238,7 +4238,7 @@ subroutine psb_dcsrspspmm(a,b,c,info) ! Estimate number of nonzeros on output. nza = a%get_nzeros() nzb = b%get_nzeros() - nzc = 2*(nza+nzb) + nzc = max(nint(0.5*(nza+nzb)),ma,mb,na,nb) call c%allocate(ma,nb,nzc) call csr_spspmm(a,b,c,info) @@ -4303,8 +4303,8 @@ contains if (nrc > 0 ) then if ((nzc+nrc)>nze) then nze = max(ma*((nzc+j-1)/j),nzc+2*nrc) - call psb_realloc(nze,c%val,info) - if (info == 0) call psb_realloc(nze,c%ja,info) + call psb_ensure_size(nze,c%val,info) + if (info == 0) call psb_ensure_size(nze,c%ja,info) if (info /= 0) return end if diff --git a/base/serial/impl/psb_s_csr_impl.F90 b/base/serial/impl/psb_s_csr_impl.F90 index 460f2cab..a0cce83d 100644 --- a/base/serial/impl/psb_s_csr_impl.F90 +++ b/base/serial/impl/psb_s_csr_impl.F90 @@ -3693,7 +3693,7 @@ subroutine psb_scsrspspmm(a,b,c,info) ! Estimate number of nonzeros on output. nza = a%get_nzeros() nzb = b%get_nzeros() - nzc = 2*(nza+nzb) + nzc = max(nint(0.5*(nza+nzb)),ma,mb,na,nb) call c%allocate(ma,nb,nzc) call csr_spspmm(a,b,c,info) @@ -3773,8 +3773,8 @@ contains if (nrc > 0 ) then if ((nzc+nrc)>nze) then nze = max(ma*((nzc+j-1)/j),nzc+2*nrc) - call psb_realloc(nze,c%val,info) - if (info == 0) call psb_realloc(nze,c%ja,info) + call psb_ensure_size(nze,c%val,info) + if (info == 0) call psb_ensure_size(nze,c%ja,info) if (info /= 0) return end if @@ -4238,7 +4238,7 @@ subroutine psb_scsrspspmm(a,b,c,info) ! Estimate number of nonzeros on output. nza = a%get_nzeros() nzb = b%get_nzeros() - nzc = 2*(nza+nzb) + nzc = max(nint(0.5*(nza+nzb)),ma,mb,na,nb) call c%allocate(ma,nb,nzc) call csr_spspmm(a,b,c,info) @@ -4303,8 +4303,8 @@ contains if (nrc > 0 ) then if ((nzc+nrc)>nze) then nze = max(ma*((nzc+j-1)/j),nzc+2*nrc) - call psb_realloc(nze,c%val,info) - if (info == 0) call psb_realloc(nze,c%ja,info) + call psb_ensure_size(nze,c%val,info) + if (info == 0) call psb_ensure_size(nze,c%ja,info) if (info /= 0) return end if diff --git a/base/serial/impl/psb_z_csr_impl.F90 b/base/serial/impl/psb_z_csr_impl.F90 index 8141fb99..784b78f6 100644 --- a/base/serial/impl/psb_z_csr_impl.F90 +++ b/base/serial/impl/psb_z_csr_impl.F90 @@ -3693,7 +3693,7 @@ subroutine psb_zcsrspspmm(a,b,c,info) ! Estimate number of nonzeros on output. nza = a%get_nzeros() nzb = b%get_nzeros() - nzc = 2*(nza+nzb) + nzc = max(nint(0.5*(nza+nzb)),ma,mb,na,nb) call c%allocate(ma,nb,nzc) call csr_spspmm(a,b,c,info) @@ -3773,8 +3773,8 @@ contains if (nrc > 0 ) then if ((nzc+nrc)>nze) then nze = max(ma*((nzc+j-1)/j),nzc+2*nrc) - call psb_realloc(nze,c%val,info) - if (info == 0) call psb_realloc(nze,c%ja,info) + call psb_ensure_size(nze,c%val,info) + if (info == 0) call psb_ensure_size(nze,c%ja,info) if (info /= 0) return end if @@ -4238,7 +4238,7 @@ subroutine psb_zcsrspspmm(a,b,c,info) ! Estimate number of nonzeros on output. nza = a%get_nzeros() nzb = b%get_nzeros() - nzc = 2*(nza+nzb) + nzc = max(nint(0.5*(nza+nzb)),ma,mb,na,nb) call c%allocate(ma,nb,nzc) call csr_spspmm(a,b,c,info) @@ -4303,8 +4303,8 @@ contains if (nrc > 0 ) then if ((nzc+nrc)>nze) then nze = max(ma*((nzc+j-1)/j),nzc+2*nrc) - call psb_realloc(nze,c%val,info) - if (info == 0) call psb_realloc(nze,c%ja,info) + call psb_ensure_size(nze,c%val,info) + if (info == 0) call psb_ensure_size(nze,c%ja,info) if (info /= 0) return end if