void read_coordinates(char *argv[]) { static FILE *fp; static char Species[20]; static double tmp0,tmp1; static int i,j; Gxyz = (double**)malloc(sizeof(double*)*(atomnum+1)); for (i=0; i<=atomnum; i++){ Gxyz[i] = (double*)malloc(sizeof(double)*60); } if ((fp = fopen(argv[2],"r")) != NULL){ printf("Read the coordinates file (%s)\n",argv[2]); /**************************************************** open the file ****************************************************/ input_open(argv[2]); /**************************************************** read data ****************************************************/ if (fp=input_find("<Atoms.SpeciesAndCoordinates") ) { for (i=1; i<=atomnum; i++){ fscanf(fp,"%i %s %lf %lf %lf %lf %lf",&j,&Species, &Gxyz[i][1],&Gxyz[i][2],&Gxyz[i][3],&tmp0,&tmp1); if (i!=j){ printf("Format error of the sequential number %i in <Atoms.SpeciesAndCoordinates\n",j); exit(0); } } if (!input_last("Atoms.SpeciesAndCoordinates>")) { /* format error */ printf("Format error for Atoms.SpeciesAndCoordinates\n"); exit(0); } } /**************************************************** input_close ****************************************************/ input_close(); } else { printf("Failure of reading the coordinates file (%s).\n",argv[2]); } for (i=1; i<=atomnum; i++){ printf("i=%i coodinates=%15.12f %15.12f %15.12f\n", i,Gxyz[i][1],Gxyz[i][2],Gxyz[i][3]); } }
void Show_DFT_DATA(char *argv[]) { FILE *fp,*fp0,*fp1,*fp2,*fp3; int Num_DatFiles,i,j,k,fp_OK; int Num_Atoms; int NGrid1_1,NGrid1_2,NGrid1_3; int NGrid2_1,NGrid2_2,NGrid2_3; double Utot1,Utot2,dU,dF; double gx,gy,gz,fx,fy,fz; double sum1,sum2; double time1,TotalTime; char SN[30][YOUSO10]; char SB[30][YOUSO10]; char SV[30][YOUSO10]; char fname[YOUSO10]; char fname0[YOUSO10]; char fname1[YOUSO10]; char fname2[YOUSO10]; char fname_dat[YOUSO10]; char fname_dat2[YOUSO10]; char fname_out1[YOUSO10]; char fname_out2[YOUSO10]; char ftmp[YOUSO10]; fname_type *fndat; int numprocs,myid; char *dir; char input_dir[300]; char *output_file; DIR *dp; struct dirent *entry; MPI_Request request; MPI_Status status; /* set up MPI */ MPI_Comm_size(mpi_comm_level1,&numprocs); MPI_Comm_rank(mpi_comm_level1,&myid); sprintf(input_dir,"%s",argv[2]); printf("%s\n",input_dir); /* print the header */ if (myid==Host_ID){ /* set dir */ dir = input_dir; /* count the number of dat files */ if(( dp = opendir(dir) ) == NULL ){ printf("could not find the directry '%s'\n",input_dir); MPI_Finalize(); exit(0); } Num_DatFiles = 0; while((entry = readdir(dp)) != NULL){ if ( strstr(entry->d_name,".dat")!=NULL ){ Num_DatFiles++; } } closedir(dp); fndat = (fname_type*)malloc(sizeof(fname_type)*Num_DatFiles); /* store the name of dat files */ if(( dp = opendir(dir) ) == NULL ){ printf("could not find the directry '%s'\n",input_dir); MPI_Finalize(); exit(0); } Num_DatFiles = 0; while((entry = readdir(dp)) != NULL){ if ( strstr(entry->d_name,".dat")!=NULL ){ sprintf(fndat[Num_DatFiles].fn,"%s/%s",input_dir,entry->d_name); Num_DatFiles++; } } closedir(dp); } /* if (myid==Host_ID) */ if (myid==Host_ID){ printf(" %2d dat files are found in the directory '%s'.\n\n\n",Num_DatFiles,input_dir); } /*********************************************************** start calculations ***********************************************************/ for (i=0; i<Num_DatFiles; i++){ sprintf(fname_dat,"%s",fndat[i].fn); input_open(fname_dat); input_int("Species.Number",&SpeciesNum,0); /* read Definition.of.Atomic.Species */ if (fp=input_find("<Definition.of.Atomic.Species")) { for (k=0; k<SpeciesNum; k++){ fscanf(fp,"%s %s %s",SN[k],SB[k],SV[k]); printf("i=%2d k=%2d %s %s\n",i,k,SB[k],SV[k]); /* SpeciesString2int(i); */ } if (! input_last("Definition.of.Atomic.Species>")) { MPI_Finalize(); exit(0); } } input_close(); } if (myid==Host_ID){ free(fndat); } MPI_Barrier(mpi_comm_level1); MPI_Finalize(); exit(0); }
void Runtest(char *mode, int argc, char *argv[]) { FILE *fp,*fp0,*fp1,*fp2,*fp3; int Num_DatFiles,i,j,k,fp_OK; int Num_Atoms; int NGrid1_1,NGrid1_2,NGrid1_3; int NGrid2_1,NGrid2_2,NGrid2_3; double Utot1,Utot2,dU,dF; double Spread1,Spread2; double Omega1,Omega2; double gx,gy,gz,fx,fy,fz; double sum1,sum2; double time1,TotalTime; char fname[YOUSO10]; char fname0[YOUSO10]; char fname1[YOUSO10]; char fname2[YOUSO10]; char fname_dat[YOUSO10]; char fname_dat2[YOUSO10]; char fname_out1[YOUSO10]; char fname_out2[YOUSO10]; char ftmp[YOUSO10]; fname_type *fndat; char operate[800]; int numprocs,myid; char *dir; char *input_dir; char *output_file; DIR *dp; struct dirent *entry; MPI_Request request; MPI_Status status; /* set up MPI */ MPI_Comm_size(MPI_COMM_WORLD1, &numprocs); MPI_Comm_rank(MPI_COMM_WORLD1, &myid); if (strcasecmp(mode,"S")==0){ input_dir = "input_example"; output_file = "runtest.result"; } else if (strcasecmp(mode,"L")==0){ input_dir = "large_example"; output_file = "runtestL.result"; } else if (strcasecmp(mode,"L2")==0){ input_dir = "large2_example"; output_file = "runtestL2.result"; } else if (strcasecmp(mode,"G")==0){ input_dir = "geoopt_example"; output_file = "runtestG.result"; } else if (strcasecmp(mode,"WF")==0){ input_dir = "wf_example"; output_file = "runtestWF.result"; } else if (strcasecmp(mode,"NEGF")==0){ input_dir = "negf_example"; output_file = "runtestNEGF.result"; } /* set Runtest_flag */ Runtest_flag = 1; /* initialize TotalTime */ TotalTime = 0.0; /* print the header */ if (myid==Host_ID){ printf("\n*******************************************************\n"); fflush(stdout); printf("*******************************************************\n"); fflush(stdout); printf(" Welcome to OpenMX Ver. %s \n",Version_OpenMX); fflush(stdout); printf(" Copyright (C), 2002-2013, T.Ozaki \n"); fflush(stdout); printf(" OpenMX comes with ABSOLUTELY NO WARRANTY. \n"); fflush(stdout); printf(" This is free software, and you are welcome to \n"); fflush(stdout); printf(" redistribute it under the constitution of the GNU-GPL.\n"); fflush(stdout); printf("*******************************************************\n"); fflush(stdout); printf("*******************************************************\n\n\n");fflush(stdout); printf("\n"); printf(" OpenMX is now in the mode to check whether OpenMX runs normally\n"); fflush(stdout); printf(" on your machine or not by comparing the stored *.out and\n"); fflush(stdout); printf(" generated *.out \n"); fflush(stdout); printf("\n");fflush(stdout); /* set dir */ dir = input_dir; /* count the number of dat files */ if(( dp = opendir(dir) ) == NULL ){ printf("could not find the directry '%s'\n",input_dir); MPI_Finalize(); exit(0); } Num_DatFiles = 0; while((entry = readdir(dp)) != NULL){ if ( strstr(entry->d_name,".dat")!=NULL ){ Num_DatFiles++; } } closedir(dp); fndat = (fname_type*)malloc(sizeof(fname_type)*Num_DatFiles); /* store the name of dat files */ if(( dp = opendir(dir) ) == NULL ){ printf("could not find the directry '%s'\n",input_dir); MPI_Finalize(); exit(0); } Num_DatFiles = 0; while((entry = readdir(dp)) != NULL){ if ( strstr(entry->d_name,".dat")!=NULL ){ sprintf(fndat[Num_DatFiles].fn,"%s/%s",input_dir,entry->d_name); Num_DatFiles++; } } closedir(dp); /* sorting fndat */ qsort(fndat, Num_DatFiles, sizeof(fname_type), stringcomp); /* for (i=0; i<Num_DatFiles; i++){ printf("i=%2d %s\n",i,fndat[i].fn); } */ } /* if (myid==Host_ID) */ sprintf(fname2,"%s",output_file); if (myid==Host_ID){ fp = fopen(fname2, "r"); if (fp!=NULL){ fclose(fp); sprintf(operate,"%s",fname2); remove(operate); } } if (myid==Host_ID){ printf(" %2d dat files are found in the directory '%s'.\n\n\n",Num_DatFiles,input_dir); } MPI_Bcast(&Num_DatFiles, 1, MPI_INT, Host_ID, MPI_COMM_WORLD1); /*********************************************************** start calculations ***********************************************************/ for (i=0; i<Num_DatFiles; i++){ if (myid==Host_ID){ sprintf(fname_dat,"%s",fndat[i].fn); } MPI_Bcast(&fname_dat, YOUSO10, MPI_CHAR, Host_ID, MPI_COMM_WORLD1); /* run openmx */ argv[1] = fname_dat; run_main(argc, argv, numprocs, myid); /*********************************************************** comparison between two files and save the result ***********************************************************/ if (myid==Host_ID){ input_open(fname_dat); input_string("System.Name",fname_dat2,"default"); input_close(); /* compare two out files */ sprintf(fname_out1,"%s.out",fname_dat2); sprintf(fname_out2,"%s/%s.out",input_dir,fname_dat2); /* generated file */ input_open(fname_out1); input_double("Utot.",&Utot1,(double)0.0); /* for Wannier functions */ if (strcasecmp(mode,"WF")==0){ input_double("Sum.of.Spreads.",&Spread1,(double)0.0); input_double("Total.Omega.=",&Omega1,(double)0.0); } input_int("Num.Grid1.",&NGrid1_1,(int)0); input_int("Num.Grid2.",&NGrid1_2,(int)0); input_int("Num.Grid3.",&NGrid1_3,(int)0); input_double("Elapsed.Time.",&time1,(double)0.0); TotalTime += time1; if (fp3=input_find("<coordinates.forces")) { fscanf(fp3,"%d",&Num_Atoms); sum1 = 0.0; for (j=1; j<=Num_Atoms; j++){ fscanf(fp3,"%d %s %lf %lf %lf %lf %lf %lf", &k,ftmp,&gx,&gy,&gz,&fx,&fy,&fz); sum1 += fx + fy + fz; } if ( ! input_last("coordinates.forces>") ) { printf("Format error for coordinates.forces\n"); } } else { sum1 = 1000.0; } input_close(); /* stored file */ input_open(fname_out2); /* Utot */ input_double("Utot.",&Utot2,(double)0.0); /* for Wannier functions */ if (strcasecmp(mode,"WF")==0){ input_double("Sum.of.Spreads.",&Spread2,(double)0.0); input_double("Total.Omega.=",&Omega2,(double)0.0); } /* grids */ input_int("Num.Grid1.",&NGrid2_1,(int)0); input_int("Num.Grid2.",&NGrid2_2,(int)0); input_int("Num.Grid3.",&NGrid2_3,(int)0); /* coordinates and forces */ if (fp3=input_find("<coordinates.forces")) { fscanf(fp3,"%d",&Num_Atoms); sum2 = 0.0; for (j=1; j<=Num_Atoms; j++){ fscanf(fp3,"%d %s %lf %lf %lf %lf %lf %lf", &k,ftmp,&gx,&gy,&gz,&fx,&fy,&fz); sum2 += fx + fy + fz; } if ( ! input_last("coordinates.forces>") ) { /* format error */ printf("Format error for coordinates.forces\n"); } } else { sum2 = 100.0; } input_close(); dU = fabs(Utot1 - Utot2); dF = fabs(sum1 - sum2); /* write the result to a file, runtest.result */ if ( (fp2 = fopen(fname2,"a")) != NULL ){ if ( (NGrid1_1!=NGrid2_1) || (NGrid1_2!=NGrid2_2) || (NGrid1_3!=NGrid2_3) ) { fprintf(fp2," Invalid comparison due to the different number of grids.\n"); fprintf(fp2," You may use a different radix for FFT.\n"); } if (strcasecmp(mode,"WF")==0){ fprintf(fp2,"%4d %-32.30s Elapsed time(s)=%8.2f diff spread=%15.12f diff Omega=%15.12f\n", i+1,fname_dat,time1,fabs(Spread1-Spread2),fabs(Omega1-Omega2)); } else{ fprintf(fp2,"%4d %-32.30s Elapsed time(s)=%8.2f diff Utot=%15.12f diff Force=%15.12f\n", i+1,fname_dat,time1,dU,dF); } if (i==(Num_DatFiles-1)){ fprintf(fp2,"\n\nTotal elapsed time (s) %11.2f\n",TotalTime); } fclose(fp2); } } } /* tell us the end of calculation */ if (myid==Host_ID){ printf("\n\n\n\n"); printf("The comparison can be found in a file '%s'.\n\n\n",output_file); } if (myid==Host_ID){ free(fndat); } MPI_Barrier(MPI_COMM_WORLD1); MPI_Finalize(); exit(0); }