I have the following schematic parallelized for-loop (using OpenMP),
char command[200];
int thread_id;
# pragma omp parallel private(thread_id)
{
thread_id = omp_get_thread_num();
# pragma omp for
for (int i = 0; i < max_value; i++) {
// Generates a text file here (.inp) with a file name of node_(thread_id).inp
std::sprintf(command, "executable.exe < node_%d.inp > node_%d.out", thread_id, thread_id);
std::system(command);
// Reads the output file node_(thread_id).out
}
}
I then compile the code with MPC 1.1.0 and GCC 8.4.0, and submit it to SLURM. The code seems to run fine at some times but I observed that there are times where the file name is wrong. For example, the .inp file becomes "nodee0.inp" or "node_0.o.o". There are also times that SLURM throws a segmentation fault error, and there are other times that there are no files written from node 0, i.e. the name of the file ends with node 1 or 2, which is against from what I expect that there should always be a "node_0".
So my question is, what could be the cause of the misnaming of the files, the segmentation fault error, and the files from the missing nodes? The problem might be from SLURM since the code works fine at other times, but I wonder if I should write or change something in the code to decrease the occurrences of these errors.
Thank you in advance.