0

I was trying to write a program for matrix vektor multiplication using MPI and C. Somehow it always gave me this error message when I was using the MPI_Barrier command:

======================================================================= = BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES

= PID 4547 RUNNING AT localhost

= EXIT CODE: 11

= CLEANING UP REMAINING PROCESSES =========================================================================

I then deleted the MPI_Barrier command and to synchronize my processes I used the sleep() function, and it worked. I then figured my code is correct. Has anyone of you ever had a similar problem? I am very confused.

The whole code looks like this:

#include <stdio.h>
#include <stdlib.h>
#include "mpi.h"
#include <unistd.h>
int main (int argc, char **argv)
{

/* MPI Parameter */
int         err;
int         size, rank;

/* loop-parameters */
int i, j, p, m, l, k, t, v, w, d, z;


int      r, q;
double **A_r;
double  *x_q;
double  *mybuf;
double  *b_r;


/* Initialize MPI-Umgebung */
err = MPI_Init (&argc, &argv);


err = MPI_Comm_rank (MPI_COMM_WORLD, &rank);
err = MPI_Comm_size (MPI_COMM_WORLD, &size);

I skipped the irrelevant part here.

 /* Output of each process */
for (p = 0; p < size; p++)
{
    if (rank == p)
    {
        printf ("Prozess %d: A_r\n", p);
        for (i = 0; i < r; i++)
        {
            for (j = 0; j < m; j++)
                printf ("%4.2f ", A_r[i][j]);
            printf ("\n");
        }

        printf ("\nProzess %d: x_q\n", p);
        for (j = 0; j < q; j++)
            printf ("%4.2f ", x_q[j]);
        printf ("\n");

        printf ("\nProzess %d: b_r\n", p);
        for (i = 0; i < r; i++)
            printf ("%4.2f ", b_r[i]);
        printf ("\n\n\n");
    }
    MPI_Barrier(MPI_COMM_WORLD);
    }
for (i = 0; i < r; i++)
    free (A_r[i]);
free (A_r);
free (x_q);
free (mybuf);
free (b_r);

err = MPI_Finalize ();

return 0;
}

EDIT: Sorry I hope this is better now. The Thing is just before the last for loop if I put "//" before the MPI_Barrier, the programm works, but if I have it actually in my code it gives me the above mentioned error.

Felix Ki
  • 1
  • 1
  • 2
    Welcome to SO. In order to help us answer your question please 1) Reduce your code to a [mcve], 2) format it properly, particularly remove huge amounts of empty lines, 3) translate relevant comments and texts to english, 4) provide the full output of the application. – Zulan Nov 13 '17 at 13:17
  • also, what is your `mpirun` command line ? – Gilles Gouaillardet Nov 13 '17 at 14:37
  • Im not quite sure what you mean. I type mpirun -np=4 ./matrix 4 4 in my terminal and enter. Im using a mac btw idk if this is relevant for the problem. I copied the full output in my post above. thank you guys so far – Felix Ki Nov 13 '17 at 15:15
  • This kind of behavior may be related to an undefined behavior. Indeed, it can remain unnoticed until a test or a minor change in the code unveils it. The error may be in the "irrelevant part"... Given the way the matrix is allocated, scattering it may be difficult, since the values are not contiguous in memory. See https://stackoverflow.com/questions/5901476/sending-and-receiving-2d-array-over-mpi or https://stackoverflow.com/questions/25628321/dynamic-memory-allocation-in-mpi/25629279#25629279 So far, it is hard to answer your question because the problem is likely elsewhere in the code! – francis Nov 13 '17 at 18:17
  • okay thanks a lot! – Felix Ki Nov 13 '17 at 19:20

0 Answers0