Мне нужна помощь для повторного запуска exe-файла для MPI-кода с многопоточностью (Matrix-Vector Multiplication) - PullRequest
0 голосов
/ 19 апреля 2020

Когда я пытался перезапустить exe-файл для mpi-кода с помощью команды многопоточности, используя C: \ Users \ m_swe \ source \ repos \ PrjCC \ MatMPI \ x64 \ Debug> mpiexe c -n 4 MatMPI .exe Я получил следующее сообщение об ошибке:

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 -----

Что мне нужно сделать, чтобы повторно запустить exe-файл, сгенерированный из скомпилированного файла в Visual Studio 2019 с многопоточностью, с помощью команды

mpiexe c -n P exefile

код работает нормально, но я не знаю, почему у меня возникает проблема, когда я пытался повторно запустить исполняемый файл с многопоточностью

код (Скомпилировано 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");


}

Также есть комментарии для улучшения кода, этот код предназначен для умножения Matrix-Vector. Обратите внимание, что код работает нормально, но я не могу перезапустить исполняемый файл

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...