Skip to content

Commit

Permalink
Updating static printing to allow parsing of atomic and net magnetic …
Browse files Browse the repository at this point in the history
…moment via API. Updating check_inputs to prevent hanging when including invalid inputs on a slurm environment.
  • Loading branch information
ltimmerman3 committed Nov 13, 2024
1 parent 832750d commit f289deb
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 16 deletions.
9 changes: 9 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
-Name
-changes

--------------
Nov 13, 2024
Name: Lucas Timmerman
Changes: (initialization.c, initialization.h, electronicGroundState.c)
1. Put check_inputs into it's own loop and added a broadcastable exit flag to trigger an exit on all processors
2. Modified printing in static file so that atomic magnetic moments can be read by api.
3. Added net magnetization to the static file
4. Added net magnetization as part of the final outputs in .out file

--------------
Oct 15, 2024
Name: Shashikant Kumar
Expand Down
27 changes: 16 additions & 11 deletions src/electronicGroundState.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ void Calculate_electronicGroundState(SPARC_OBJ *pSPARC) {
if (pSPARC->d3Flag == 1) {
fprintf(output_fp,"DFT-D3 correction :%18.10E (Ha)\n", pSPARC->d3Energy[0]);
}
if (pSPARC->spin_typ > 0) {
fprintf(output_fp,"Net magnetization :%18.10E (Bohr magneton)\n", pSPARC->netM[0]);
}
if (pSPARC->ixc[3] != 0) {
fprintf(output_fp,"vdWDF energy :%18.10E (Ha)\n", pSPARC->vdWDFenergy);
}
Expand Down Expand Up @@ -174,17 +177,19 @@ void Calculate_electronicGroundState(SPARC_OBJ *pSPARC) {
fprintf(static_fp,"%18.10E %18.10E %18.10E\n",
pSPARC->forces[3*i],pSPARC->forces[3*i+1],pSPARC->forces[3*i+2]);
}
if (pSPARC->spin_typ == 1) {
fprintf(static_fp, "Atomic magnetization along Z-dir within Radius 2 Bohr: (Bohr magneton)\n");
for (i = 0; i < pSPARC->n_atom; i++) {
fprintf(static_fp,"%18.10E\n", pSPARC->AtomMag[i]);
}
}
if (pSPARC->spin_typ == 2) {
fprintf(static_fp, "Atomic magnetization along X,Y,Z-dir within Radius 2 Bohr: (Bohr magneton)\n");
for (i = 0; i < pSPARC->n_atom; i++) {
fprintf(static_fp,"%18.10E %18.10E %18.10E\n",
pSPARC->AtomMag[3*i],pSPARC->AtomMag[3*i+1],pSPARC->AtomMag[3*i+2]);
if (pSPARC->spin_typ > 0) {
fprintf(static_fp, "Net magnetization (Bohr magneton): %18.10E\n", pSPARC->netM[0]);
if (pSPARC->spin_typ == 1) {
fprintf(static_fp, "Atomic magnetization along Z-dir within Radius 2 Bohr (Bohr magneton):\n");
for (i = 0; i < pSPARC->n_atom; i++) {
fprintf(static_fp,"%18.10E\n", pSPARC->AtomMag[i]);
}
} else if (pSPARC->spin_typ == 2) {
fprintf(static_fp, "Atomic magnetization along X,Y,Z-dir within Radius 2 Bohr (Bohr magneton):\n");
for (i = 0; i < pSPARC->n_atom; i++) {
fprintf(static_fp,"%18.10E %18.10E %18.10E\n",
pSPARC->AtomMag[3*i],pSPARC->AtomMag[3*i+1],pSPARC->AtomMag[3*i+2]);
}
}
}
fclose(static_fp);
Expand Down
2 changes: 1 addition & 1 deletion src/include/initialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void SPARC_Input_MPI_create(MPI_Datatype *pSPARC_INPUT_MPI);
* @param argc The number of arguments that are passed to the program.
* @param argv The array of strings representing command line arguments.
*/
void check_inputs(SPARC_INPUT_OBJ *pSPARC_Input, int argc, char *argv[]);
void check_inputs(SPARC_INPUT_OBJ *pSPARC_Input, int argc, char *argv[], int *exit_flag);


/**
Expand Down
16 changes: 12 additions & 4 deletions src/initialization.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,19 +238,26 @@ void Initialize(SPARC_OBJ *pSPARC, int argc, char *argv[]) {
if (rank == 0) printf("\nCreating SPARC_INPUT_MPI datatype took %.3f ms\n",(t2-t1)*1000);
#endif

int exit_flag;
if (rank == 0) {
#ifdef DEBUG
printf("Initializing ...\n");
t1 = MPI_Wtime();
#endif
// check input arguments and read filename
check_inputs(&SPARC_Input, argc, argv);
check_inputs(&SPARC_Input, argc, argv, &exit_flag);

#ifdef DEBUG
t2 = MPI_Wtime();
printf("\nChecking inputs parsed by commandline took %.3f ms\n",(t2-t1)*1000);
t1 = MPI_Wtime();
#endif
}

MPI_Bcast(&exit_flag, 1, MPI_INT, 0, MPI_COMM_WORLD);
if (exit_flag == 1) exit(EXIT_FAILURE);

if (rank ==0) {
set_defaults(&SPARC_Input, pSPARC); // set default values

#ifdef DEBUG
Expand Down Expand Up @@ -496,7 +503,7 @@ void Initialize(SPARC_OBJ *pSPARC, int argc, char *argv[]) {
/**
* @brief Check input arguments and read filename.
*/
void check_inputs(SPARC_INPUT_OBJ *pSPARC_Input, int argc, char *argv[]) {
void check_inputs(SPARC_INPUT_OBJ *pSPARC_Input, int argc, char *argv[], int *exit_flag) {
#ifdef DEBUG
printf("Checking input arguments parsed by command line.\n");
#endif
Expand Down Expand Up @@ -529,7 +536,8 @@ void check_inputs(SPARC_INPUT_OBJ *pSPARC_Input, int argc, char *argv[]) {
for (i = 1; i < argc-1; i++) {
if (strcmp(argv[i],"--help") == 0 || strcmp(argv[i],"-h") == 0) {
print_usage();
exit(EXIT_FAILURE);
*exit_flag = 1;
return;
}
if (strcmp(argv[i],"-name") == 0) {
name_flag = 'Y';
Expand All @@ -549,7 +557,7 @@ void check_inputs(SPARC_INPUT_OBJ *pSPARC_Input, int argc, char *argv[]) {

if (name_flag != 'Y') {
print_usage();
exit(EXIT_FAILURE);
*exit_flag = 1;
}
}

Expand Down

0 comments on commit f289deb

Please sign in to comment.