dimanche 24 octobre 2021

Speeding Up MPI When Writing to File

I'm implementing Conoway's Game of Life using MPI, everything works fine but when writing the board to a file my performance is terrible. I've commented out the write to file block of code to test it.

1000x1000Test
With Output File: 1.8653
Without Output File: 0.620289

Here's the code:

 int aBoard[sliceSize][N];
        //Write to file.
        if (rank == 0) {

            output << "Generation " << currentGen + 1 << ":" << std::endl;
            //Write current slice of board to file

            for (int i = 0; i < sliceSize; ++i) {
                for (int j = 0; j < N; ++j) {
                    char q = '.';
                    if (mySlice[i][j] == 1)
                        q = '*';
                    output << q << '\t';
                }
                output << std::endl;
            }


            //receive the other board's slices and write to file
            for (int i = 1; i < size; i++) {
                MPI_Recv(&aBoard[0][0], N * sliceSize, MPI_INT, i, 1, MPI_COMM_WORLD, &Stat);
                for (int x = 0; x < sliceSize; x++) {
                    for (int y = 0; y < N; y++) {
                        char q = '.';
                        if (aBoard[x][y] == 1)
                            q = '*';
                        output << q << '\t';

                    }
                    output << std::endl;

                }
            }
            output << std::endl << std::endl;
        } else {
            //send the slice to the first rank
            MPI_Send(&mySlice[0][0], N * sliceSize, MPI_INT, 0, 1, MPI_COMM_WORLD);
        }

Is there any changes I could make that would potentially improve performance?

Thank you

Aucun commentaire:

Enregistrer un commentaire