Hi all,
I am developping a parallell version of Delaunay's Triangulation and I
have a big problem dealing with MPI.
I define a derived datatype (using recursivity) based on the following
data structure:
typedef struct
{
double coordX;
double coordY;
} Punto;
typedef struct
{
Punto punto1;
Punto punto2;
Punto punto3;
} Triangulo;
typedef struct
{
Punto *puntos;
int *infoPuntos;
Triangulo *triangulos;
int *infoTriangulos;
} MsgTriangulacion;
You can see that I use dynamic memory in "MsgTriangulacion". I do this
as well as I don't now the number of the elements of the vectors I
want to define until execution time. I have no problem defining and
filling the structure, I reserve dynamic memory by means of the
traditional "malloc" way.
I have coded a function to commit the MPI type that represents the
message I want to pass between cluster nodes. Here it is:
void crearMensajeMPI(MPI_Datatype *msgTri, MsgTriangulacion paqDatos,
int numPuntos, int numTriangulos)
{
MPI_Aint doubleExtent, intExtent, puntExtent, triangExtent;
MPI_Type_extent(MPI_DOUBLE, &doubleExtent);
MPI_Type_extent(MPI_INT, &intExtent);
/* Aplicamos tipos derivados de forma recursiva */
/* 1. Tipo "punt" */
/* --------------- */
MPI_Datatype punt;
/* Descripci??n del tipo estructurado */
MPI_Datatype oldtypes1[2] = {MPI_DOUBLE,
MPI_DOUBLE};
int blockcounts1[2] = {1,
1};
MPI_Aint offsets1[2] = {0,
doubleExtent};
/* Definici??n del tipo estructurado */
MPI_Type_struct(2, blockcounts1, offsets1, oldtypes1, &punt);
MPI_Type_commit(&punt);
MPI_Type_extent(punt, &puntExtent);
/* 2. Tipo "triang" */
/* ---------------- */
MPI_Datatype triang;
/* Descripci??n del tipo estructurado */
MPI_Datatype oldtypes2[3] = {punt,
punt,
punt};
int blockcounts2[3] = {1,
1,
1};
MPI_Aint offsets2[3] = {0,
puntExtent,
2 * puntExtent};
/* Definici??n del tipo estructurado */
MPI_Type_struct(3, blockcounts2, offsets2, oldtypes2, &triang);
MPI_Type_commit(&triang);
MPI_Type_extent(triang, &triangExtent);
/* 3. Tipo "msgTri" */
/* ---------------- */
/* Descripci??n del tipo estructurado */
MPI_Datatype oldtypes3[4] = {punt,
MPI_INT,
triang,
MPI_INT};
int blockcounts3[4] = {numPuntos,
numPuntos,
numTriangulos,
numTriangulos};
MPI_Aint dirs[5];
MPI_Address(&paqDatos, &dirs[0]);
MPI_Address(&(paqDatos.puntos), &dirs[1]);
MPI_Address(&(paqDatos.infoPuntos), &dirs[2]);
MPI_Address(&(paqDatos.triangulos), &dirs[3]);
MPI_Address(&(paqDatos.infoTriangulos), &dirs[4]);
MPI_Aint offsets3[4] = {dirs[1] - dirs[0],
dirs[2] - dirs[0],
dirs[3] - dirs[0],
dirs[4] - dirs[0]};
/* Definici??n del tipo estructurado */
MPI_Type_struct(4, blockcounts3, offsets3, oldtypes3, msgTri);
MPI_Type_commit(msgTri);
}
Now I'm trying to pass the message from a single node to another one.
So here is what NODE 0 does ("Empaquetar" function just fills the
structure with the convenient values) to send the message:
MsgTriangulacion paqDatos;
paqDatos.puntos = (Punto *)malloc(numPuntos * sizeof(Punto));
paqDatos.infoPuntos = (int *)malloc(numPuntos * sizeof(int));
paqDatos.triangulos = (Triangulo *)malloc(numTriangulos *
sizeof(Triangulo));
paqDatos.infoTriangulos = (int *)malloc(numTriangulos * sizeof(int));
nube.Empaquetar(paqDatos);
nube.~Espacio();
MPI_Datatype msgTri;
crearMensajeMPI(&msgTri, paqDatos, numPuntos, numTriangulos);
MPI_Send(&paqDatos, 1, msgTri, 1, 0, MPI_COMM_WORLD);
And here is what NODE 1 does to receive the message:
MsgTriangulacion paqDatos2;
paqDatos2.puntos = (Punto *)malloc(numPuntos * sizeof(Punto));
paqDatos2.infoPuntos = (int *)malloc(numPuntos * sizeof(int));
paqDatos2.triangulos = (Triangulo *)malloc(numTriangulos *
sizeof(Triangulo));
paqDatos2.infoTriangulos = (int *)malloc(numTriangulos * sizeof(int));
MPI_Datatype msgTri;
crearMensajeMPI(&msgTri, paqDatos2, numPuntos, numTriangulos);
MPI_Recv(&paqDatos2, 1, msgTri, 0, MPI_ANY_TAG,
MPI_COMM_WORLD, &status);
for(int i=0;i<numPuntos;i++)
{
std::cout << paqDatos2.puntos[i].coordX << std::endl;
std::cout << paqDatos2.puntos[i].coordY << std::endl;
std::cout << "-------" << std::endl;
}
for(int j=0;j<numTriangulos;j++)
{
std::cout << paqDatos2.triangulos[j].punto1.coordX << std::endl;
std::cout << paqDatos2.triangulos[j].punto1.coordY << std::endl;
std::cout << paqDatos2.triangulos[j].punto2.coordX << std::endl;
std::cout << paqDatos2.triangulos[j].punto2.coordY << std::endl;
std::cout << paqDatos2.triangulos[j].punto3.coordX << std::endl;
std::cout << paqDatos2.triangulos[j].punto3.coordY << std::endl;
std::cout << "-------" << std::endl;
}
}
The problem is that the final test shows only 0's in the second
structure (paqDatos2). The first thing I would like to know is if it
is possible to send this kind of "dynamic" message using MPI, as I
haven't seen it in the web. The second one is to know if I am making
any big error... any help will be very welcome :).
Thanks in advance and sorry for the lenght of the message,
Miguel Ángel González
|