@@ -774,38 +774,57 @@ void find_local_kpthf(SPARC_OBJ *pSPARC)
774774double estimate_memory_exx (const SPARC_OBJ * pSPARC )
775775{
776776 double memory_exx = 0.0 ;
777- int Nd = pSPARC -> Nd * pSPARC -> Nspinor ;
778- int Ns = pSPARC -> Nstates ;
779- int Nspin = pSPARC -> Nspin ;
780- int Nkpts_sym = pSPARC -> Nkpts_sym ;
781- int npband = pSPARC -> npband ;
782- int npkpt = pSPARC -> npkpt ;
783- int Nkpts_hf_red = pSPARC -> Nkpts_hf_red ;
784- int Nkpts_hf = pSPARC -> Nkpts_hf ;
785- int Nband = pSPARC -> Nband_bandcomm ;
786- int type_size = (pSPARC -> isGammaPoint == 1 ) ? sizeof (double ) : sizeof (double _Complex );
787- int dmcomm_size = pSPARC -> npNd ;
777+ /* ******** The following block was changed by Sayan. For high memory estimates, there was int overflow ********** */
778+ // int Nd = pSPARC->Nd * pSPARC->Nspinor;
779+ // int Ns = pSPARC->Nstates;
780+ // int Nspin = pSPARC->Nspin;
781+ // int Nkpts_sym = pSPARC->Nkpts_sym;
782+ // int npband = pSPARC->npband;
783+ // int npkpt = pSPARC->npkpt;
784+ // int Nkpts_hf_red = pSPARC->Nkpts_hf_red;
785+ // int Nkpts_hf = pSPARC->Nkpts_hf;
786+ // int Nband = pSPARC->Nband_bandcomm;
787+ // int type_size = (pSPARC->isGammaPoint == 1) ? sizeof(double) : sizeof(double _Complex);
788+ // int dmcomm_size = pSPARC->npNd;
789+ /* ***************************************************************************************************************** */
790+
791+ long long Nd = (long long )pSPARC -> Nd * pSPARC -> Nspinor ;
792+ long long Ns = pSPARC -> Nstates ;
793+ long long Nspin = pSPARC -> Nspin ;
794+ long long Nkpts_sym = pSPARC -> Nkpts_sym ;
795+ long long npband = pSPARC -> npband ;
796+ long long npkpt = pSPARC -> npkpt ;
797+ long long Nkpts_hf_red = pSPARC -> Nkpts_hf_red ;
798+ long long Nkpts_hf = pSPARC -> Nkpts_hf ;
799+ long long Nband = pSPARC -> Nband_bandcomm ;
800+
801+ size_t type_size = (pSPARC -> isGammaPoint == 1 ) ? sizeof (double ) : sizeof (double _Complex );
802+ long long dmcomm_size = pSPARC -> npNd ;
788803
789804 if (pSPARC -> ExxAcc == 0 ) {
790805 // storage of psi outer
791- int len_full_tot = Nd * Ns * Nkpts_hf_red * Nspin ;
806+ // int len_full_tot = Nd * Ns * Nkpts_hf_red * Nspin; // to avoid int overflow
807+ long long len_full_tot = Nd * Ns * Nkpts_hf_red * Nspin ;
792808 memory_exx += (double ) len_full_tot * type_size * 2 ;
793809 // memory for constructing Vx
794810 if (pSPARC -> isGammaPoint == 1 ) {
795811 // int index
796812 memory_exx += (double ) Ns * Ns * sizeof (int ) * 2 ;
797813 // for poissons equations
798- int ncol = (pSPARC -> ExxMemBatch == 0 ) ? (Ns * Ns ) : pSPARC -> ExxMemBatch ;
814+ // int ncol = (pSPARC->ExxMemBatch == 0) ? (Ns * Ns) : pSPARC->ExxMemBatch; // to avoid int overflow
815+ long long ncol = (pSPARC -> ExxMemBatch == 0 ) ? (Ns * Ns ) : pSPARC -> ExxMemBatch ;
799816 memory_exx += (double ) ncol * Nd * (2 + 2 * (dmcomm_size > 1 )) * type_size ;
800817 } else {
801818 // int index
802819 memory_exx += (double ) Ns * Ns * sizeof (int ) * Nkpts_hf * 3 ;
803820 // for poissons equations
804- int ncol = (pSPARC -> ExxMemBatch == 0 ) ? (Ns * Ns * Nkpts_hf ) : pSPARC -> ExxMemBatch ;
821+ // int ncol = (pSPARC->ExxMemBatch == 0) ? (Ns * Ns * Nkpts_hf) : pSPARC->ExxMemBatch; // to avoid int overflow
822+ long long ncol = (pSPARC -> ExxMemBatch == 0 ) ? (Ns * Ns * Nkpts_hf ) : pSPARC -> ExxMemBatch ;
805823 memory_exx += (double ) ncol * Nd * (2 + 2 * (dmcomm_size > 1 )) * type_size ;
806824 }
807825 } else {
808- int len_full_tot = Nd * Ns * Nkpts_hf_red * Nspin ;
826+ // int len_full_tot = Nd * Ns * Nkpts_hf_red * Nspin; // to avoid int overflow
827+ long long len_full_tot = Nd * Ns * Nkpts_hf_red * Nspin ;
809828 if (pSPARC -> isGammaPoint == 1 ) {
810829 // storage of ACE operator in dmcomm and kptcomm_topo
811830 memory_exx += (double ) len_full_tot * type_size * (npband + 1 ) * npkpt ;
@@ -815,7 +834,8 @@ double estimate_memory_exx(const SPARC_OBJ *pSPARC)
815834 // int index
816835 memory_exx += (double ) Nband * Ns * 2 * sizeof (int );
817836 // for poissons equations
818- int ncol = (pSPARC -> ExxMemBatch == 0 ) ? (Nband * Nband ) : pSPARC -> ExxMemBatch ;
837+ // int ncol = (pSPARC->ExxMemBatch == 0) ? (Nband * Nband) : pSPARC->ExxMemBatch; // to avoid int overflow
838+ long long ncol = (pSPARC -> ExxMemBatch == 0 ) ? (Nband * Nband ) : pSPARC -> ExxMemBatch ;
819839 memory_exx += (double ) ncol * Nd * (2 + 2 * (dmcomm_size > 1 )) * type_size ;
820840 } else {
821841 // storage of ACE operator in dmcomm and kptcomm_topo
@@ -828,7 +848,8 @@ double estimate_memory_exx(const SPARC_OBJ *pSPARC)
828848 // int index
829849 memory_exx += (double ) Ns * Nband * Nkpts_sym * 3 * sizeof (int );
830850 // for poissons equations
831- int ncol = (pSPARC -> ExxMemBatch == 0 ) ? (Nband * Nband * Nkpts_sym ) : pSPARC -> ExxMemBatch ;
851+ // int ncol = (pSPARC->ExxMemBatch == 0) ? (Nband * Nband * Nkpts_sym) : pSPARC->ExxMemBatch; // to avoid int overflow
852+ long long ncol = (pSPARC -> ExxMemBatch == 0 ) ? (Nband * Nband * Nkpts_sym ) : pSPARC -> ExxMemBatch ;
832853 memory_exx += (double ) ncol * Nd * (2 + 2 * (dmcomm_size > 1 )) * type_size ;
833854
834855 }
0 commit comments