Openmp with ofstream和system命令

时间:2016-05-24 14:42:27

标签: c++ system openmp stringstream ofstream

我使用openmp

时遇到问题

在其他要并行化的操作中,我需要读取一个文件,编辑内容并将其保存到另一个文件中,以便为入口提供一个我将要启动的可执行文件

出于性能原因,循环实际上是一个并行化的递归。

问题是我的外部可执行文件无法读取我编写和关闭的输入文件

你有什么想法吗?谢谢

要在最简单的情况下重现问题我创建了一个小程序:

global

1 个答案:

答案 0 :(得分:0)

感谢你的回答NoseKnowsAll

事实上,我已经尝试过添加一个关键区域,但情况更糟

4/1000文件没有严重的可读性, 56/1000文件无法通过关键

读取
for (N = 1; N <= max; N++)
{
    string l = "R:\\SIM\\"+to_string(N) + ".net";
    #pragma omp critical
    {
        ofstream o;
        o.open(l, ios::out | ios::trunc);
        if (o)
        {
            o <<  s.str();
        }
        else
        {
            cout << "Impossible d'ouvrir le fichier de sortie" << endl;
        }
        o.close();
    }
    string commande = "\"R:\\LTspiceIV\\scad3.exe\" -b "+l+" &";
    int retour=  system(commande.c_str());
}