I guess this question has been asked before, but unfortunately, I have not been able to find any answer yet. Sorry if I missed some. In this case, it would be nice to point me to these. Thanks.
I have a program which uses a number of large (2- and 3-dimensional, but contiguous in memory) arrays such as array2[t][x]
and array3[t][x][y]
. My program fills these arrays step by step, i.e. at some point all x (or x and y) for given t are calculated and afterwards stored in array2[x][t]
(or array3[t][x][y]
). As the program is run on a cluster which has run time constraints implemented, I would like to read-out the arrays to the hard disk at least before the wall time is over in order to read them into the same arrays again when restarting the program so that these first entries do not have to be calculated again, but can be used right away again (i.e. all the entries have to be at the same spot again). I do not need the data in human readable form, so it could also be saved in binary format.
So, what is the best (and perhaps most efficient) way to do these procedures, i.e. both reading-out and reading-in, in C (or C++)? As the arrays get filled step by step, it might be good to do the read-out after each step (or after every 10th step or so), I guess. (Might fstream
be something to consider perhaps?)
I am very happy for any suggestion. Thanks a lot!
EDIT: Perhaps to clarify: I am not asking how arrays are stored in memory, but how to read and write them from memory from/to hard disk. Thanks for the suggestions so far!