I need assistance to re-run exe file for MPI code with multithreads (Matrix-Vector Multiplication)

0

When I tried to re-run the exe file for mpi code with multithreads command by using C:\Users\m_swe\source\repos\PrjCC\MatMPI\x64\Debug>mpiexec -n 4 MatMPI.exe I got the below error message :

C:\Users\m_swe\source\repos\PrjCC\MatMPI\x64\Debug>mpiexec -n 4 MatMPI.exe
sendcount = 2500 disp = 0
sendcount = 2500 disp = 2500
sendcount = 2500 disp = 5000
sendcount = 2500 disp = 7500

job aborted:
[ranks] message

[0-2] terminated

[3] process exited without calling finalize

---- error analysis -----

[3] on DESKTOP-E6DV16D
MatMPI.exe ended prematurely and may have crashed. exit code 0xc0000005

---- error analysis -----

What I have to do to re-run exe file generated from compiled file by visual studio 2019 with multi threads by using command

mpiexec -n P exefile

the code is working fine but I don't know why I have issue when I tried to re-run exe file with multi threads

the code is (Compiled by visual studio 2019 - C/C++ MPI - Matrix-Vector Multiplication )

#include <iostream> 
#include <mpi.h> 
#include <time.h>
#include <iomanip>

using namespace std;

const int WIDTH = 100;
const int HEIGHT = 100;


//matrix in two dimension in memory!! 


void readMatricVect(double A[WIDTH][HEIGHT], double x[HEIGHT])
{
    for (int i = 0; i < WIDTH; i++)
        for (int j = 0; j < HEIGHT; j++)
            A[i][j] = 1;
    for (int j = 0; j < HEIGHT; j++)
        x[j] = 2;
}
void dispResult(double C[WIDTH])
{
    std::cout << fixed;
    for (int i = 0; i < WIDTH; i++) {
        cout << std::setprecision(2) << C[i] << "  ";
    }
    cout << endl;
}

void MultMatVectP2P(int argc, char** argv, double A[WIDTH][HEIGHT], double x[HEIGHT], double b[WIDTH]) // using point-to-point communication
{
    int rank, size;
    double tempValue = 0;
    MPI_Init(&argc, &argv);
    MPI_Comm_size(MPI_COMM_WORLD, &size);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    double timer = MPI_Wtime();
    //double A[WIDTH][HEIGHT];
    //double x[HEIGHT], b[WIDTH];
    int upperBound, lowerBound = 0;
    // Master controls worksharing.. 
    if (rank == 0)
    {
        // Send to each node its portion of A to be processed 
        int portionSize = WIDTH / size;
        for (int i = 0; i < size; i++)
        {
            lowerBound = i * portionSize;
            upperBound = (i + 1)*portionSize;
            // let the last node process the remainder 
            if (i == (size - 1))
                upperBound += (HEIGHT - portionSize * size);
            if (i > 0)// Do not send to master node!! 
            {
                // Send to node i the lower & upper bounds the A portion 
                //and complete vector x 
                MPI_Send(&lowerBound, 1, MPI_INT, i, 0, MPI_COMM_WORLD);
                MPI_Send(&upperBound, 1, MPI_INT, i, 0, MPI_COMM_WORLD);
                MPI_Send(&A[lowerBound][0], (upperBound - lowerBound)*HEIGHT,
                    MPI_DOUBLE, i, 0, MPI_COMM_WORLD);
                MPI_Send(&x[0], HEIGHT, MPI_DOUBLE, i, 0, MPI_COMM_WORLD);
            }
        }
        // master perform part of the job... 
        for (int i = 0; i < portionSize; i++)
        {
            tempValue = 0;
            for (int j = 0; j < HEIGHT; j++)
                tempValue += A[i][j] * x[j];
            b[i] = tempValue;
        }
        //Get the results in order, each node would send their boundaries and data part 
        for (int i = 1; i < size; i++)
        {
            MPI_Recv(&lowerBound, 1, MPI_INT, i, 0, MPI_COMM_WORLD, MPI_STATUSES_IGNORE);
            MPI_Recv(&upperBound, 1, MPI_INT, i, 0, MPI_COMM_WORLD, MPI_STATUSES_IGNORE);
            MPI_Recv(&x[lowerBound], (upperBound - lowerBound), MPI_DOUBLE, i, 0,
                MPI_COMM_WORLD, MPI_STATUSES_IGNORE);
        }

    }
    else // the rest of the workers do their parts 
    {
        //Receive the inputs 
        MPI_Recv(&lowerBound, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUSES_IGNORE);
        MPI_Recv(&upperBound, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUSES_IGNORE);
        MPI_Recv(&A[lowerBound][0], (upperBound - lowerBound)*WIDTH, MPI_DOUBLE, 0, 0,
            MPI_COMM_WORLD, MPI_STATUSES_IGNORE);
        MPI_Recv(&x, HEIGHT, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, MPI_STATUSES_IGNORE);
        cout << "Node:" << rank << " Received from:" << lowerBound << " to " << upperBound - 1
            << endl;
        double *result = new double[upperBound - lowerBound];
        //Do the job 
        for (int i = lowerBound, resultCounter = 0; i < upperBound; i++, resultCounter++)
        {
            tempValue = 0;
            for (int j = 0; j < HEIGHT; j++)
                tempValue += A[i][j] * x[j];
            result[resultCounter] = tempValue;
        }
        //send the results 
        MPI_Send(&lowerBound, 1, MPI_INT, 0, 0, MPI_COMM_WORLD);
        MPI_Send(&upperBound, 1, MPI_INT, 0, 0, MPI_COMM_WORLD);
        MPI_Send(&result[0], upperBound - lowerBound, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD);
        delete[] result;
    }
    timer = MPI_Wtime() - timer;
    MPI_Finalize();
    std::cout << fixed;
    cout << "\n\nPoint To Point Time Needed for all ops = " << std::setprecision(15)<<timer << " Seconds" << endl;
    //system("PAUSE");

}


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


    //Point to Point 

    double A[WIDTH][HEIGHT];
    double x[HEIGHT], b[WIDTH];
    readMatricVect(A, x);
    MultMatVectP2P(argc, argv,A,x,b);
    cout << "\nMatrix Vector Multiplication using Point-To-Point Communication" << endl;
    dispResult(b);
    system("PAUSE");


}

Also is there any comments to enhance code , this code is for Matrix-Vector Multiplication. Note the code is working fine but I cannot re-run exe file

c++
visual-studio
mpi

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0