C++ code runs on Mac with multithreading, file will not open in Ubuntu

115 Views Asked by At

Running C++ code using Repast HPC 2.1 on an Ubuntu 14.04 VirtualBox VM. This code has been proven to work when run in XCode on a Mac laptop. I'm currently trying to make the existing code run in Ubuntu. Make runs successfully on the code in Ubuntu, but when trying to call mpirun -n 4, I receive the following error, indicating that the file will not open properly:

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

This is using multiple threads (4), which I've heard can be an issue when opening files in Ubuntu, but I'm not sure how to fix it if this is the problem.

The error is generated by the file.fail() call in this method:

#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();
}

When the full filepath is passed as a string to file.open() in line 2 of the method, still produces the same error.

Is there some reference or library I am missing that is provided by XCode?

Thanks!

0

There are 0 best solutions below