/*---------------------------------------------------------------------- exx_interface_openmx.c: 07/JAN/2010 Coded by M. Toyoda ----------------------------------------------------------------------*/ #include #include #include #include #include "openmx_common.h" #include "exx.h" #include "exx_log.h" #include "exx_debug.h" #include "exx_interface_openmx.h" #include "exx_step1.h" #include "exx_step2.h" #include "exx_vector.h" #include "exx_index.h" #include "exx_file_eri.h" #include "exx_rhox.h" #define PATHLEN 256 static int g_step = 0; MPI_Comm g_exx_mpicomm = MPI_COMM_NULL; dcomplex *****g_exx_DM; double g_exx_U[2]; int g_exx_switch; int g_exx_switch_output_DM; int g_exx_switch_rhox; static double time_step1; static double time_step2; /*---------------------------------------------------------------------- Initialization of EXX for OpenMX ----------------------------------------------------------------------*/ void EXX_on_OpenMX_Init(MPI_Comm comm) { int i, j, l, m, k, system_type, myrank, nproc; double pvec[9]; /* primitive translational vectors */ double v[3]; int natom, nspec; double *atom_v, *spec_rc; int *atom_sp, *spec_nb; double w_scr, rc_cut; int nbmax; int **spec_l, **spec_m, **spec_n, *spec_nmesh; double ****pao_fr, **pao_xr; int lmax, mul, nmesh, nb, nmul, nm; int iep, nep, Gc_AN, Cwan, tno0, Gh_AN, Hwan, tno1; const int *exx_atm1, *exx_atm2; double time0, time1; /* MPI information */ g_exx_mpicomm = comm; MPI_Comm_size(g_exx_mpicomm, &nproc); MPI_Comm_rank(g_exx_mpicomm, &myrank); /* start logging */ EXX_Log_Open(); #ifdef EXX_USE_MPI EXX_Log_Print("MPI MODE (NPROC= %d)\n", nproc); #else EXX_Log_Print("SERIAL MODE\n"); #endif EXX_Log_Print(" MYRANK= %d\n", myrank); EXX_Log_Print("\n"); /* solver type */ switch (Solver) { case 2: /* cluster */ EXX_Log_Print("SOLVER= CLUSTER\n"); system_type = EXX_SYSTEM_CLUSTER; rc_cut = 0.0; w_scr = 0.0; break; case 3: /* band */ EXX_Log_Print("SOLVER= PERIODIC\n"); system_type = EXX_SYSTEM_PERIODIC; rc_cut = 10.0 / BohrR; /* 10 Angstrom */ w_scr = 0.0; break; default: EXX_ERROR("EXX is available for 'CLUSTER' or 'BAND' solvers."); } /* user values */ if (g_exx_rc_cut > 1e-10) { rc_cut = g_exx_rc_cut; } if (g_exx_w_scr > 1e-10) { w_scr = g_exx_w_scr; } if (EXX_SYSTEM_PERIODIC==system_type && rc_cut <1e-10) { EXX_ERROR("finite rc_cut is required for periodic mode."); } /* swithces */ EXX_Log_Print("SKIPPING STEP1 = %d\n", g_exx_skip1); EXX_Log_Print("SKIPPING STEP2 = %d\n", g_exx_skip2); EXX_Log_Print("CACHDIR= %s\n", g_exx_cachedir); EXX_Log_Print("LIBERI_LMAX= %d\n", g_exx_liberi_lmax); EXX_Log_Print("LIBERI_NGRID= %d\n", g_exx_liberi_ngrid); EXX_Log_Print("LIBERI_NGL= %d\n", g_exx_liberi_ngl); EXX_Log_Print("OUTPUT DM= %d\n", g_exx_switch_output_DM); EXX_Log_Print("\n"); /* primitive translational vectors */ pvec[0] = tv[1][1]; pvec[1] = tv[1][2]; pvec[2] = tv[1][3]; pvec[3] = tv[2][1]; pvec[4] = tv[2][2]; pvec[5] = tv[2][3]; pvec[6] = tv[3][1]; pvec[7] = tv[3][2]; pvec[8] = tv[3][3]; natom = atomnum; nspec = SpeciesNum; /* allocation */ atom_v = (double*)malloc(sizeof(double)*3*natom); atom_sp = (int*)malloc(sizeof(int)*natom); spec_rc = (double*)malloc(sizeof(double)*nspec); spec_nb = (int*)malloc(sizeof(int)*nspec); /* atomic positions */ for (i=0; i EXX Initialized\n"); } EXX_Log_Print("EXX Initiatlized:\n"); EXX_Log_Print(" natom= %d\n", EXX_natom(g_exx)); EXX_Log_Print(" nbmax= %d\n", EXX_nbmax(g_exx)); EXX_Log_Print("\n"); EXX_Log_Print("Atoms:\n"); EXX_Log_Print(" # : X Y Z RC NB\n"); for (i=0; i Overlaps (NOP=%5d)\n", EXX_Number_of_OP(g_exx)); } /* STEP2: calculation of ERIs */ dtime(&time0); { EXX_Step2(g_exx); } dtime(&time1); time_step2 = time1 - time0; if (Host_ID==myrank) { printf(" ERIs (NEP=%10d)\n", EXX_Number_of_EP(g_exx)); } /* free memory */ free(atom_v); free(atom_sp); free(spec_rc); free(spec_nb); for (i=0; i1.0) { den = 1.0; }*/ sum = eri[i] * den; /*i = (Anum+ib1-1)*H_n + (Bnum+ib2-1);*/ i = (Anum+ib1_ep-1)*H_n + (Bnum+ib2_ep-1); local_H[i] += -w*sum; den = exx_CDM[iep1[j]][ib1_ep][ib2_ep].r; /*if (den<0.0) { den = 0.0; }*/ /*if (den>1.0) { den = 1.0; }*/ local_Ux += -0.5*w*sum*den; } } /*local_H[i] += -0.5*w*sum;*/ /*local_Ux += -0.5*w*sum*exx_CDM[iep1[j]][ib1_ep][ib2_ep];*/ } } } /* loop of j */ free(eri); } #if 0 /* gather data */ if (EXX_ROOT_RANK==myid) { for (iproc=0; iprocnbmax) { nbmax=nb; } } /* 1d array */ nbuf = nbmax*nbmax*2; buffer = (double*)malloc(sizeof(double)*nbuf); for (iep=0; iep