Skip to content

Commit

Permalink
cherry-pick b4a27883 for Molcas: fixed inconsistency in the spatial N…
Browse files Browse the repository at this point in the history
…PDM binary file format.
  • Loading branch information
naokin authored and bogdanoff committed Oct 22, 2019
1 parent 153bd69 commit a01dab6
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 9 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ ifeq ($(MOLPRO), yes)

endif

ifeq ($(MOLCAS), yes)
MOLCAS_BLOCK= -DMOLCAS
endif

FLAGS = -I${MKLFLAGS} -I$(INCLUDE1) -I$(INCLUDE2) -I$(NEWMATINCLUDE) -I$(BOOSTINCLUDE) -I$(MOLPROINCLUDE) \
-I$(HOME)/modules/generate_blocks/ -I$(HOME)/modules/onepdm -I$(HOME)/modules/twopdm/ \
-I$(HOME)/modules/npdm -I$(HOME)/modules/two_index_ops -I$(HOME)/modules/three_index_ops -I$(HOME)/modules/four_index_ops -std=c++0x \
Expand Down Expand Up @@ -162,7 +166,7 @@ ifeq ($(USE_MPI), yes)
endif


OPT += $(OPENMP_FLAGS) -DBLAS -DUSELAPACK $(MPI_OPT) $(I8) $(B56) $(MOLPRO_BLOCK) -DFAST_MTP -D_HAS_CBLAS ${MKLOPT} ${UNITTEST}
OPT += $(OPENMP_FLAGS) -DBLAS -DUSELAPACK $(MPI_OPT) $(I8) $(B56) $(MOLPRO_BLOCK) $(MOLCAS_BLOCK) -DFAST_MTP -D_HAS_CBLAS ${MKLOPT} ${UNITTEST}

SRC_genetic = genetic/CrossOver.C genetic/Evaluate.C genetic/GAInput.C genetic/GAOptimize.C genetic/Generation.C genetic/Mutation.C genetic/RandomGenerator.C genetic/ReadIntegral.C

Expand Down
6 changes: 6 additions & 0 deletions modules/npdm/onepdm_container.C
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,16 @@ void Onepdm_container::save_spatial_npdm_binary(const int &i, const int &j)
{
char file[5000];
sprintf (file, "%s%s%d.%d%s", dmrginp.save_prefix().c_str(),"/spatial_onepdm.", i, j,".bin");
#ifndef MOLCAS
std::ofstream ofs(file, std::ios::binary);
boost::archive::binary_oarchive save(ofs);
save << spatial_onepdm;
ofs.close();
#else
FILE* f = fopen(file,"wb");
fwrite(spatial_onepdm.data(),sizeof(double),spatial_onepdm.size(),f);
fclose(f);
#endif
}
}

Expand Down
6 changes: 6 additions & 0 deletions modules/npdm/threepdm_container.C
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,16 @@ void Threepdm_container::save_spatial_npdm_binary(const int &I, const int &J)

char file[5000];
sprintf (file, "%s%s%d.%d%s", dmrginp.save_prefix().c_str(),"/spatial_threepdm.",I,J,".bin");
#ifndef MOLCAS
std::ofstream ofs(file, std::ios::binary);
//boost::archive::binary_oarchive save(ofs);
ofs.write( (char*)(spatial_threepdm.data), sizeof(double)*spatial_threepdm.get_size());
ofs.close();
#else
FILE* f = fopen(file,"wb");
fwrite(spatial_threepdm.data(),sizeof(double),spatial_threepdm.size(),f);
fclose(f);
#endif
}
}
else{
Expand Down
6 changes: 6 additions & 0 deletions modules/npdm/twopdm_container.C
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,16 @@ void Twopdm_container::save_spatial_npdm_binary(const int &i, const int &j)
{
char file[5000];
sprintf (file, "%s%s%d.%d%s", dmrginp.save_prefix().c_str(),"/spatial_twopdm.", i, j,".bin");
#ifndef MOLCAS
std::ofstream ofs(file, std::ios::binary);
boost::archive::binary_oarchive save(ofs);
save << spatial_twopdm;
ofs.close();
#else
FILE* f = fopen(file,"wb");
fwrite(spatial_twopdm.data(),sizeof(double),spatial_twopdm.size(),f);
fclose(f);
#endif
}
}

Expand Down
2 changes: 2 additions & 0 deletions molcas/block_calldmrg.C
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,11 @@ void block_calldmrg (
switch (N_pdm) {
case 1:
fcon << "onepdm" << endl;
fcon << "new_npdm_code" << endl;
break;
case 2:
fcon << "twopdm" << endl;
fcon << "new_npdm_code" << endl;
break;
case 3:
fcon << "threepdm" << endl;
Expand Down
16 changes: 8 additions & 8 deletions molcas/sortNpdm.C
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void sort1pdm (FORTINT N_act, FORTINT iRoot, FORTINT jRoot)
if(mpigetrank() == 0) {

std::ostringstream ifname;
ifname << "./node0/spatial_binary_onepdm." << iRoot << "." << jRoot << ".bin";
ifname << "./node0/spatial_onepdm." << iRoot << "." << jRoot << ".bin";

std::ostringstream ofname;
ofname << "./SORTED1PDM." << iRoot << "." << jRoot << ".0";
Expand All @@ -30,9 +30,9 @@ void sort1pdm (FORTINT N_act, FORTINT iRoot, FORTINT jRoot)
// sort <i,j> (in row-major) to G(i,j) (in col-major)
// i.e. G(i,j) = <i,j>

int Ndum;
fread(&Ndum,sizeof(int),1,ifp);
assert(Ndum == N_act);
// int Ndum;
// fread(&Ndum,sizeof(int),1,ifp);
// assert(Ndum == N_act);

double *xbuf = new double[N2];
fread(xbuf,sizeof(double),N2,ifp);
Expand Down Expand Up @@ -62,7 +62,7 @@ void sort2pdm (FORTINT N_act, FORTINT iRoot, FORTINT jRoot)
if(mpigetrank() == 0) {

std::ostringstream ifname;
ifname << "./node0/spatial_binary_twopdm." << iRoot << "." << jRoot << ".bin";
ifname << "./node0/spatial_twopdm." << iRoot << "." << jRoot << ".bin";

std::ostringstream ofname;
ofname << "./SORTED2PDM." << iRoot << "." << jRoot << ".0";
Expand All @@ -82,9 +82,9 @@ void sort2pdm (FORTINT N_act, FORTINT iRoot, FORTINT jRoot)
// sort <i,j,k,l> (in row-major) to G(i,l,j,k) (in col-major)
// i.e. G(i,j,k,l) = <i,k,l,j>

int Ndum;
fread(&Ndum,sizeof(int),1,ifp);
assert(Ndum == N_act);
// int Ndum;
// fread(&Ndum,sizeof(int),1,ifp);
// assert(Ndum == N_act);

double *xbuf = new double[N4];
fread(xbuf,sizeof(double),N4,ifp);
Expand Down

0 comments on commit a01dab6

Please sign in to comment.