program ended prematurely and may have crashed. exit code 0xc0000005

First and foremost, there are ways to debug an MPI application, which should really be your top priority. A general approach for multi-process applications is to pause at the beginning of your application e.g. with a getchar() then attach to each process with a debugger as described here:

  • compile, link and start running your MPI program (you may wish to put a read statement early on to hold the program while you do the next steps)
  • attach to one of the currently running MPI processes: DebugAttach to Process brings up a dialogue box which lists Available Processes. You should see NUM instances (where N is from mpiexec -n NUM) of your executable. Select all of these and click on Attach. You can now debug by adding breakpoints etc. To move between MPI processes use the Process drop-down menu just above the code listing.

Having said that, at least one of the problems is with this part: int **array = new int*[(close - start)*cols]; (in the receive part of the application). You allocate the first dimension but not the second, so all pointers in the first dimension are uninitialized.

Change it to something like:

        int *array = new int[(close - start) * cols];
        MPI_Recv(array, (close - start) *cols, MPI_INT, 0, 3, MPI_COMM_WORLD, MPI_STATUSES_IGNORE);
        for (int i = start; i < close; i++) {
            for (int j = 0; j < cols; j++) {
                cout << array[(i - start) * cols];
                res += array[(i - start) * cols] * v_array[i];
                cout << res;
            }
        }
        delete[] array;

Or if you really want to use a 2D array, copy the initialization code from the sending part:

        int rows = close - start;
        int **array = new int*[rows];
        int size1 = rows * cols;
        array[0] = new int[size1];
        for (int j = 1; j < rows; j++) {
            array[j] = &array[0][j*cols];
        }

The second problem is that v_array, being a global is not initialized in your receiver processes. Remember that in MPI each process is an independent program. So you should initialize v_array always, i.e. regardless of pro_id.

        for (int i = 0; i < rows; i++) {
            v_array[i] = 1;
        }

2 thoughts on “program ended prematurely and may have crashed. exit code 0xc0000005”

  1. whoah this blog is wonderful i really like reading your articles. Keep up the great paintings! You realize, a lot of people are hunting round for this info, you could help them greatly.

    Reply

Leave a Comment