Skip to content

Commit d3a2ac1

Browse files
Merge pull request #260 from sayanbhowmik/master
2 parents 14a2ee1 + 68b725f commit d3a2ac1

3 files changed

Lines changed: 45 additions & 18 deletions

File tree

ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
-Name
44
-changes
55

6+
--------------
7+
December 03, 2025
8+
Name: Sayan Bhowmik
9+
Changes: (src/xc/exx/exactExchangeInitialization.c)
10+
1. Datatype change in memory estimate function to avoid integer overflow for high memory situations.
11+
612
--------------
713
November 28, 2025
814
Name: Tian Tian

src/initialization.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3722,7 +3722,7 @@ void write_output_init(SPARC_OBJ *pSPARC) {
37223722
}
37233723

37243724
fprintf(output_fp,"***************************************************************************\n");
3725-
fprintf(output_fp,"* SPARC (version November 25, 2025) *\n");
3725+
fprintf(output_fp,"* SPARC (version December 03, 2025) *\n");
37263726
fprintf(output_fp,"* Copyright (c) 2020 Material Physics & Mechanics Group, Georgia Tech *\n");
37273727
fprintf(output_fp,"* Distributed under GNU General Public License 3 (GPL) *\n");
37283728
fprintf(output_fp,"* Start time: %s *\n",c_time_str);

src/xc/exx/exactExchangeInitialization.c

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -774,38 +774,57 @@ void find_local_kpthf(SPARC_OBJ *pSPARC)
774774
double 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

Comments
 (0)