I've written a code that works perfectly with -g -o, but I'm having trouble making this work with parallelization: I've tried with #pragma omp critical however, while running, the program halts at the line ofstream outputFile (path, ios :: app); указывает, что, несмотря на использование #pragma , написание файлов остается небезопасным.
Здесь есть пример того, что я попробовал:
Код: Выделить всё
class Loss
{
public:
double loss_value;
string choosen_loss;
string path;
Loss(string loss_function, string filepath)
{
choosen_loss = loss_function;
path = filepath;
};
void calculator(variant NN_outputs, variant targets, int data_size)
{
#pragma omp critical //for safe writing;
if (choosen_loss == "MSE")
{
choice = MSE;
loss_value += choice(NN_outputs, targets) / (double)data_size;
}
else if (choosen_loss == "BCE")
{
choice = BCE;
loss_value += choice(NN_outputs, targets) / (double)data_size;
}
else if (choosen_loss == "MEE")
{
choice = MEE;
loss_value += choice(NN_outputs, targets) / (double)data_size;
}
else
{
cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79499639/file-writing-while-compiling-with-flag-fopenmp[/url]
Мобильная версия