This commit is contained in:
Ian Jauslin 2023-06-14 14:19:27 -04:00
parent d15f58b61e
commit 7ab59aca48
4 changed files with 52 additions and 8 deletions

View File

@ -13,8 +13,18 @@ which will place a binary at `build/nstrophy`.
The syntax for the execution of Nstrophy is The syntax for the execution of Nstrophy is
```bash ```bash
./build/nstrophy [-p parameters] [-s savefile] <command> ./build/nstrophy [-p parameters] [-s savefile] [-u u_outfile] <command>
``` ```
* `parameters` is a list of parameters for the computation, see
[Parameters](#parameters)
* `savefile` is a file where the last step of the computation is saved in
binary format so that the computation can be resumed after it has terminated,
see
[Interrupting and resuming the computation](#interrupting-and-resuming-the-computation).
* `u_outfile` is a file to which the final u is written in plain text format,
which can be used as an initial condition for a future computation.
Nstrophy is written in C. The Makefile uses the GNU C Compiler. Nstrophy is written in C. The Makefile uses the GNU C Compiler.
@ -114,7 +124,7 @@ should be a `;` sperated list of `key=value` pairs. The possible keys are
norm. norm.
# Interrupting/resuming the computation # Interrupting and resuming the computation
The computation can be interrupted by sending Nstrophy the `SIGINT` signal The computation can be interrupted by sending Nstrophy the `SIGINT` signal
(e.g. by pressing `Ctrl-C`.) When Nstrophy receives the `SIGINT` signal, it (e.g. by pressing `Ctrl-C`.) When Nstrophy receives the `SIGINT` signal, it

View File

@ -60,7 +60,7 @@ int print_usage();
int print_params(nstrophy_parameters parameters, char* initfile_str, char* drivingfile_str, FILE* file); int print_params(nstrophy_parameters parameters, char* initfile_str, char* drivingfile_str, FILE* file);
// read command line arguments // read command line arguments
int read_args(int argc, const char* argv[], char** params, unsigned int* command, unsigned int* nthreads, char** savefile_str); int read_args(int argc, const char* argv[], char** params, unsigned int* command, unsigned int* nthreads, char** savefile_str, char** utfile_str);
int read_params(char* param_str, nstrophy_parameters* parameters, char** initfile_str, char** drivingfile_str); int read_params(char* param_str, nstrophy_parameters* parameters, char** initfile_str, char** drivingfile_str);
int set_parameter(char* lhs, char* rhs, nstrophy_parameters* parameters, bool* setN1, bool* setN2, char** initfile_str, char** drivingfile_str); int set_parameter(char* lhs, char* rhs, nstrophy_parameters* parameters, bool* setN1, bool* setN2, char** initfile_str, char** drivingfile_str);
@ -94,14 +94,16 @@ int main (
_Complex double* u0; _Complex double* u0;
_Complex double *g; _Complex double *g;
char* savefile_str=NULL; char* savefile_str=NULL;
char* utfile_str=NULL;
char* initfile_str=NULL; char* initfile_str=NULL;
char* drivingfile_str=NULL; char* drivingfile_str=NULL;
FILE* savefile=NULL; FILE* savefile=NULL;
FILE* utfile=NULL;
command=0; command=0;
// read command line arguments // read command line arguments
ret=read_args(argc, argv, &param_str, &command, &nthreads, &savefile_str); ret=read_args(argc, argv, &param_str, &command, &nthreads, &savefile_str, &utfile_str);
if(ret<0){ if(ret<0){
return(-1); return(-1);
} }
@ -152,6 +154,15 @@ int main (
} }
} }
// open utfile (do this after closing init file)
if(utfile_str!=NULL){
utfile=fopen(utfile_str,"w");
if(utfile==NULL){
fprintf(stderr,"Error opening file '%s' for writing: %s\n", utfile_str, strerror(errno));
return(-1);
}
}
// print parameters // print parameters
print_params(parameters, initfile_str, drivingfile_str, stderr); print_params(parameters, initfile_str, drivingfile_str, stderr);
print_params(parameters, initfile_str, drivingfile_str, stdout); print_params(parameters, initfile_str, drivingfile_str, stdout);
@ -173,7 +184,7 @@ int main (
// register signal handler to handle aborts // register signal handler to handle aborts
signal(SIGINT, sig_handler); signal(SIGINT, sig_handler);
signal(SIGTERM, sig_handler); signal(SIGTERM, sig_handler);
enstrophy(parameters.K1, parameters.K2, parameters.N1, parameters.N2, parameters.final_time, parameters.nu, parameters.delta, parameters.L, parameters.adaptive_tolerance, parameters.adaptive_factor, parameters.max_delta, parameters.adaptive_norm, u0, g, parameters.irreversible, parameters.algorithm, parameters.print_freq, parameters.starting_time, nthreads, savefile, (char*)argv[0], param_str, savefile_str); enstrophy(parameters.K1, parameters.K2, parameters.N1, parameters.N2, parameters.final_time, parameters.nu, parameters.delta, parameters.L, parameters.adaptive_tolerance, parameters.adaptive_factor, parameters.max_delta, parameters.adaptive_norm, u0, g, parameters.irreversible, parameters.algorithm, parameters.print_freq, parameters.starting_time, nthreads, savefile, utfile, (char*)argv[0], param_str, savefile_str);
} }
else if(command==COMMAND_QUIET){ else if(command==COMMAND_QUIET){
quiet(parameters.K1, parameters.K2, parameters.N1, parameters.N2, parameters.final_time, parameters.nu, parameters.delta, parameters.L, parameters.adaptive_tolerance, parameters.adaptive_factor, parameters.max_delta, parameters.adaptive_norm, parameters.starting_time, u0, g, parameters.irreversible, parameters.algorithm, nthreads, savefile); quiet(parameters.K1, parameters.K2, parameters.N1, parameters.N2, parameters.final_time, parameters.nu, parameters.delta, parameters.L, parameters.adaptive_tolerance, parameters.adaptive_factor, parameters.max_delta, parameters.adaptive_norm, parameters.starting_time, u0, g, parameters.irreversible, parameters.algorithm, nthreads, savefile);
@ -191,12 +202,17 @@ int main (
fclose(savefile); fclose(savefile);
} }
// close utfile
if (utfile!=NULL){
fclose(utfile);
}
return(0); return(0);
} }
// usage message // usage message
int print_usage(){ int print_usage(){
fprintf(stderr, "usage:\n nstrophy [-t nthreads] [-p parameters] [-s savefile] <command>\n\n"); fprintf(stderr, "usage:\n nstrophy [-t nthreads] [-p parameters] [-s savefile] [-u u_outfile] <command>\n\n");
return(0); return(0);
} }
@ -301,13 +317,15 @@ int print_params(
#define CP_FLAG_PARAMS 1 #define CP_FLAG_PARAMS 1
#define CP_FLAG_NTHREADS 2 #define CP_FLAG_NTHREADS 2
#define CP_FLAG_SAVEFILE 3 #define CP_FLAG_SAVEFILE 3
#define CP_FLAG_UTFILE 4
int read_args( int read_args(
int argc, int argc,
const char* argv[], const char* argv[],
char** params, char** params,
unsigned int* command, unsigned int* command,
unsigned int* nthreads, unsigned int* nthreads,
char** savefile_str char** savefile_str,
char** utfile_str
){ ){
int i; int i;
int ret; int ret;
@ -331,6 +349,9 @@ int read_args(
case 's': case 's':
flag=CP_FLAG_SAVEFILE; flag=CP_FLAG_SAVEFILE;
break; break;
case 'u':
flag=CP_FLAG_UTFILE;
break;
default: default:
fprintf(stderr, "unrecognized option '-%c'\n", *ptr); fprintf(stderr, "unrecognized option '-%c'\n", *ptr);
print_usage(); print_usage();
@ -358,6 +379,11 @@ int read_args(
*savefile_str=(char*)argv[i]; *savefile_str=(char*)argv[i];
flag=0; flag=0;
} }
// savefile
else if(flag==CP_FLAG_UTFILE){
*utfile_str=(char*)argv[i];
flag=0;
}
// computation to run // computation to run
else{ else{
if(strcmp(argv[i], "uk")==0){ if(strcmp(argv[i], "uk")==0){

View File

@ -126,6 +126,7 @@ int uk(
} }
} }
// TODO: update handling of savefile
// save final entry to savefile // save final entry to savefile
write_vec_bin(u, K1, K2, savefile); write_vec_bin(u, K1, K2, savefile);
@ -155,6 +156,7 @@ int enstrophy(
double starting_time, double starting_time,
unsigned int nthreads, unsigned int nthreads,
FILE* savefile, FILE* savefile,
FILE* utfile,
// for interrupt recovery // for interrupt recovery
char* cmd_string, char* cmd_string,
char* params_string, char* params_string,
@ -307,6 +309,11 @@ int enstrophy(
} }
} }
// save final u to utfile in txt format
if(utfile!=NULL){
write_vec(u, K1, K2, utfile);
}
ns_free_tmps(u, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, fft1, fft2, ifft, algorithm); ns_free_tmps(u, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, fft1, fft2, ifft, algorithm);
return(0); return(0);
} }
@ -378,6 +385,7 @@ int quiet(
step=next_step; step=next_step;
} }
// TODO: update handling of savefile
// save final entry to savefile // save final entry to savefile
write_vec(u, K1, K2, savefile); write_vec(u, K1, K2, savefile);

View File

@ -36,7 +36,7 @@ typedef struct fft_vects {
int uk( int K1, int K2, int N1, int N2, double final_time, double nu, double delta, double L, double adaptive_tolerance, double adaptive_factor, double max_delta, unsigned int adaptive_norm, _Complex double* u0, _Complex double* g, bool irreversible, unsigned int algorithm, double print_freq, double starting_time, unsigned int nthreadsl, FILE* savefile); int uk( int K1, int K2, int N1, int N2, double final_time, double nu, double delta, double L, double adaptive_tolerance, double adaptive_factor, double max_delta, unsigned int adaptive_norm, _Complex double* u0, _Complex double* g, bool irreversible, unsigned int algorithm, double print_freq, double starting_time, unsigned int nthreadsl, FILE* savefile);
// compute enstrophy and alpha // compute enstrophy and alpha
int enstrophy( int K1, int K2, int N1, int N2, double final_time, double nu, double delta, double L, double adaptive_tolerance, double adaptive_factor, double max_delta, unsigned int adaptive_norm, _Complex double* u0, _Complex double* g, bool irreversible, unsigned int algorithm, double print_freq, double starting_time, unsigned int nthreads, FILE* savefile, char* cmd_string, char* params_string, char* savefile_string); int enstrophy( int K1, int K2, int N1, int N2, double final_time, double nu, double delta, double L, double adaptive_tolerance, double adaptive_factor, double max_delta, unsigned int adaptive_norm, _Complex double* u0, _Complex double* g, bool irreversible, unsigned int algorithm, double print_freq, double starting_time, unsigned int nthreads, FILE* savefile, FILE* utfile, char* cmd_string, char* params_string, char* savefile_string);
// compute solution as a function of time, but do not print anything (useful for debugging) // compute solution as a function of time, but do not print anything (useful for debugging)
int quiet( int K1, int K2, int N1, int N2, double final_time, double nu, double delta, double L, double adaptive_tolerance, double adaptive_factor, double max_delta, unsigned int adaptive_norm, double starting_time, _Complex double* u0, _Complex double* g, bool irreversible, unsigned int algorithm, unsigned int nthreads, FILE* savefile); int quiet( int K1, int K2, int N1, int N2, double final_time, double nu, double delta, double L, double adaptive_tolerance, double adaptive_factor, double max_delta, unsigned int adaptive_norm, double starting_time, _Complex double* u0, _Complex double* g, bool irreversible, unsigned int algorithm, unsigned int nthreads, FILE* savefile);