Write restart command to savefile

This commit is contained in:
2023-04-12 19:05:01 -04:00
parent 0b0894839d
commit c00c311528
5 changed files with 81 additions and 7 deletions

View File

@@ -2,6 +2,7 @@
#include "io.h"
#include <math.h>
#include <stdlib.h>
#include <string.h>
// compute solution as a function of time
int uk(
@@ -93,7 +94,11 @@ int eea(
unsigned int running_avg_window,
unsigned int starting_time,
unsigned int nthreads,
FILE* savefile
FILE* savefile,
// for interrupt recovery
char* cmd_string,
char* params_string,
char* savefile_string
){
_Complex double* u;
_Complex double* tmp1;
@@ -186,9 +191,9 @@ int eea(
avg_print_short_en+=enstrophy/short_len;
}
if(t % print_freq ==0 && t>0){
if(t % print_freq ==0 && t>starting_time){
// compute averages
if (t > running_avg_window) {
if (t > running_avg_window + starting_time) {
avg_e=save_print_short_e[nr_print_in_window]*((double)short_len/running_avg_window);
avg_a=save_print_short_a[nr_print_in_window]*((double)short_len/running_avg_window);
avg_en=save_print_short_en[nr_print_in_window]*((double)short_len/running_avg_window);
@@ -226,7 +231,7 @@ int eea(
}
}
if(t>running_avg_window && t%print_freq==0){
if(t>running_avg_window + starting_time && t%print_freq==0){
fprintf(stderr,"%d % .8e % .8e % .8e % .8e % .8e % .8e % .8e\n",t,t*delta, avg_a, avg_e, avg_en, alpha, energy, enstrophy);
printf("%8d % .15e % .15e % .15e % .15e % .15e % .15e % .15e\n",t,t*delta, avg_a, avg_e, avg_en, alpha, energy, enstrophy);
}
@@ -237,6 +242,24 @@ int eea(
if (savefile==NULL){
savefile=stderr;
}
fprintf(savefile,"# Interrupted computation. Resume with\n");
// command to resume
fprintf(savefile,"#! ");
fprintf(savefile, cmd_string);
// params
// allocate buffer for params
char* params=calloc(sizeof(char), strlen(params_string));
strcpy(params, params_string);
remove_entry(params, "starting_time");
remove_entry(params, "init");
remove_entry(params, "nsteps");
fprintf(savefile," -p \"%s;starting_time=%u;nsteps=%u;init=file:%s\"", params, t+1, nsteps-t-1, savefile_string);
free(params);
fprintf(savefile," energy\n");
break;
}
}