Samuel
Samuel

Reputation: 19

Why don't files open when I add MPI?

When my program works without MPI, then everything is fine with opening files, but when I add MPI, the files do not open. Why is that?
My code:

void fileEntry(string path, int n) {

    ofstream fout;

    fout.open(path);
    if (!fout.is_open()) {
        cout << "File open error";
    }
    else {
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                fout << rand() % 100 << " ";
            }
            fout << "\n";
        }
    }

    fout.close();
}

int main(int argc, char** argv) {

    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &WORLD_RANK);
    MPI_Comm_size(MPI_COMM_WORLD, &WORLD_SIZE);

    if (WORLD_RANK == 0) {
        // размерность
        int dimension = 0;
        cout << "Введите размерность матрицы:\n";
        cin >> dimension;

        // записываем данные в файлы
        fileEntry("MatrixA.txt", dimension);
        fileEntry("MatrixB.txt", dimension);
    ...
}

This code gives twice: File open error.
I start the project in 7 processes, but it doesn't matter, because I do opening files specifically in only one 0 process. I don’t need the file to open 7 times, I need 1 time.
And so not only with the opening, but in general with any work with files.

Upvotes: 0

Views: 361

Answers (1)

Levantail Yolo
Levantail Yolo

Reputation: 26

I didn't have enough reputation to comment, so posting here.

According to you comments, errno 13 stands for 'permission denied' and errno 2 - 'No such file or directory'

First i would suggest to try use full filepath, and then try to provide right permission to the file or directory.

Upvotes: 1

Related Questions