1

在 Ubuntu 14.04 VirtualBox VM 上使用 Repast HPC 2.1 运行 C++ 代码。此代码已被证明在 Mac 笔记本电脑上的 XCode 中运行时有效。我目前正在尝试使现有代码在 Ubuntu 中运行。Make在Ubuntu中的代码上运行成功,但是在尝试调用mpirun -n 4时,收到如下错误,提示文件无法正常打开:

file open fail /home/repasthpc/Desktop/hpcmodel/angiogenesis-osteogenesis-simulator/concFiles/c100forC.txt
file open fail /home/repasthpc/Desktop/hpcmodel/angiogenesis-osteogenesis-simulator/concFiles/c100forC.txt
file open fail /home/repasthpc/Desktop/hpcmodel/angiogenesis-osteogenesis-simulator/concFiles/c100forC.txt
file open fail /home/repasthpc/Desktop/hpcmodel/angiogenesis-osteogenesis-simulator/concFiles/c100forC.txt

这是使用多线程 (4),我听说在 Ubuntu 中打开文件时可能会出现问题,但如果这是问题,我不确定如何解决。

错误是file.fail()由此方法中的调用生成的:

#include <fstream>
#include <string>
#include <vector>
#include <math.h>
#include "repast_hpc/Random.h"
#include "SolubleMap.h"
#include "BoneModel.h"

using namespace std;

void SolubleMap::releaseVEGF(std::string filename){
    ifstream file;
    file.open(filename.c_str());

    int row=time; //time
    int column=ydim; // location

    if(file.fail()){
        cerr << "file open fail" << endl;
    }

    else{
        this->VEGFConcentration = new double*[row]; // memory allocated for elements of rows
        for(int j = 0; j < row; j++){ 
            this->VEGFConcentration[j] = new double[column]; // memory allocated for elements of columns
            for(int i = 0; i < column; i++){
                if (!(file >> this->VEGFConcentration[j][i])){
                    std::cerr << "error while reading file";
                    break;
                }
            }
            if (!file) break;
        }
    }
    file.close();
}

当完整的文件路径作为字符串传递到file.open()方法的第 2 行时,仍然会产生相同的错误。

XCode 是否提供了一些我缺少的参考或库?

谢谢!

4

0 回答 0