Skip to content

Commit

Permalink
Versión 1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
S0LERA committed May 6, 2019
1 parent 829dcc4 commit b2972bf
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 4 deletions.
Binary file added Documentacion.pdf
Binary file not shown.
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
compilar:
mpicc ./src/pract2.c -o ./src/pract2 -lX11

Renderizado:
(cd src && mpirun -n 1 pract2)

limpiar:
rm ./src/pract2
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ Se desea crear un programa de renderizado gráfico con MPI. Un proceso se encarg

### Versión 0.8
- Código del padre listo.

### Versión 1.5
- Programa completado.
- Añadido Makefile.

### Versión 1.8
- Documentación Añadida.
Binary file removed src/pract2
Binary file not shown.
43 changes: 39 additions & 4 deletions src/pract2.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ int main(int argc, char *argv[])
MPI_Comm commPadre;
int tag;
MPI_Status status;
int buf[5];
int hijos = 4;
int buf[5];
int error[hijos];

MPI_Init(&argc, &argv);
Expand All @@ -75,17 +75,17 @@ int main(int argc, char *argv[])
MPI_Comm_get_parent(&commPadre);
if ((commPadre == MPI_COMM_NULL) && (rank == 0))
{

initX();

/* Codigo del maestro */
MPI_Comm_spawn("spawnP2", MPI_ARGV_NULL, hijos, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &commPadre, error);
MPI_Comm_spawn("pract2", MPI_ARGV_NULL, hijos, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &commPadre, error);

for (int i = 0; i < 160000; i++)
for (int i = 0; i < 400*400; i++)
{
MPI_Recv(&buf, 5, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG, commPadre, MPI_STATUS_IGNORE);
dibujaPunto(buf[0], buf[1], buf[2], buf[3], buf[4]);
}
sleep(5);

/*En algun momento dibujamos puntos en la ventana algo como
dibujaPunto(x,y,r,g,b); */
Expand All @@ -94,7 +94,42 @@ int main(int argc, char *argv[])
{
/* Codigo de todos los trabajadores */
/* El archivo sobre el que debemos trabajar es foto.dat */
MPI_File f;
int lineas_hijo = 400 / hijos;
int linea_inicio = lineas_hijo * rank;
int linea_final = 0;
if (rank == hijos - 1)
{
linea_final = 400;
}
else
{
linea_final = linea_inicio + lineas_hijo;
}

int bloque = lineas_hijo * 400 * 3 * sizeof(unsigned char);
int bloque_hijo = bloque * rank;
unsigned char tripleta[3];

MPI_File_open(MPI_COMM_WORLD, "foto.dat", MPI_MODE_RDONLY, MPI_INFO_NULL, &f);
MPI_File_set_view(f, bloque_hijo, MPI_UNSIGNED_CHAR, MPI_UNSIGNED_CHAR, "native", MPI_INFO_NULL);

for (int i = linea_inicio; i < linea_final; i++)
{
for (int j = 0; j < 400; j++)
{
MPI_File_read(f, tripleta, 3, MPI_UNSIGNED_CHAR, &status);
buf[0] = j;
buf[1] = i;
buf[2] = (int)tripleta[0];
buf[3] = (int)tripleta[1];
buf[4] = (int)tripleta[2];
MPI_Send(&buf, 5, MPI_INT, 0, 1, commPadre);
}
}
MPI_File_close(&f);
}

MPI_Finalize();
return 0;
}

0 comments on commit b2972bf

Please sign in to comment.