-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmodules-io.cpp
More file actions
64 lines (56 loc) · 1.91 KB
/
modules-io.cpp
File metadata and controls
64 lines (56 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* ***************************************************************************
* This file is part of the SymPhas library, a framework for implementing
* solvers for phase-field problems with compile-time symbolic algebra.
*
* Copyright (c) 2018-2021 by Steven A. Silber and Mikko Karttunen
*
* SymPhas is free software, which can be redistributed or modified under
* the terms of the GNU Lesser General Public License (LGPL) as published
* by the Free Software Foundation; LGPL version 3, or later versions at
* your choice.
*
* SymPhas is distributed with the faith that it will be helpful and
* practical but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details.
*
* ***************************************************************************
*/
#include "configured-defs.h"
#ifdef USING_CONF
#include "modules-conf.h"
#else
#include "modules-io.h"
#endif
const char* symphas::get_record_name(const char* dir) {
const char file_name[] = CHECKPOINT_DIR "/progress.txt";
size_t out_len = std::strlen(dir) + std::strlen(file_name) + 2;
char* out = new char[out_len];
snprintf(out, out_len, "%s/%s", dir, file_name);
return out;
}
FILE* symphas::open_record(const char* name) {
FILE* f;
if ((f = fopen(name, "a")) == 0) {
fprintf(SYMPHAS_ERR, "error opening backup configuration file '%s'\n",
name);
exit(1001);
}
return f;
}
void symphas::record_index(const char* dir, SaveParams const& save, int index) {
#ifdef USING_MPI
if (symphas::parallel::is_host_node()) {
#endif
const char* name = get_record_name(dir);
FILE* f = open_record(name);
fprintf(f, CONFIG_INDEX_PREFIX "%d\n", index);
if (index == save.get_stop()) {
fprintf(f, CONFIG_INDEX_PREFIX SIMULATION_DONE_KEY "\n");
}
fclose(f);
delete[] name;
#ifdef USING_MPI
}
#endif
}