U1 Programa4 S12021
U1 Programa4 S12021
/*****************************************************************************
* FILE: omp_dotprod_serial.c
* DESCRIPTION:
* This simple program is the serial version of a dot product and the
* first of four codes used to show the progression from a serial program to a
* hybrid MPI/OpenMP program. The relevant codes are:
* - omp_dotprod_serial.c - Serial version
* - omp_dotprod_openmp.c - OpenMP only version
* - omp_dotprod_mpi.c - MPI only version
* - omp_dotprod_hybrid.c - Hybrid MPI and OpenMP version
* SOURCE: Blaise Barney
* LAST REVISED: 06/02/17 Blaise Barney
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
printf("Starting omp_dotprod_serial\n");
free (a);
free (b);
}
============================
/*****************************************************************************
* FILE: omp_dotprod_openmp.c
* DESCRIPTION:
* This simple program is the OpenMP version of a dot product and the
* second of four codes used to show the progression from a serial program to a
* hybrid MPI/OpenMP program. The relevant codes are:
* - omp_dotprod_serial.c - Serial version
* - omp_dotprod_openmp.c - OpenMP only version
* - omp_dotprod_mpi.c - MPI only version
* - omp_dotprod_hybrid.c - Hybrid MPI and OpenMP version
* SOURCE: Blaise Barney
* LAST REVISED: 06/02/17 Blaise Barney
******************************************************************************/
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
/*
SECRETARÍA DE EDUCACIÓN PÚBLICA
TECNOLÓGICO NACIONAL DE MÉXICO
INSTITUTO TECNOLÓGICO DE CIUDAD MADERO
Perform the dot product in an OpenMP parallel region for loop with
a sum reduction
For illustration purposes:
- Explicitly sets number of threads
- Each thread keeps track of its partial sum
*/
free (a);
free (b);
}
============================
/*****************************************************************************
* FILE: omp_dotprod_mpi.c
* DESCRIPTION:
* This simple program is the MPI version of a dot product and the third
* of four codes used to show the progression from a serial program to a
* hybrid MPI/OpenMP program. The relevant codes are:
* - omp_dotprod_serial.c - Serial version
* - omp_dotprod_openmp.c - OpenMP only version
* - omp_dotprod_mpi.c - MPI only version
* - omp_dotprod_hybrid.c - Hybrid MPI and OpenMP version
* SOURCE: Blaise Barney
* LAST REVISED: 06/02/17 Blaise Barney
******************************************************************************/
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
/* MPI Initialization */
MPI_Init (&argc, &argv);
MPI_Comm_size (MPI_COMM_WORLD, &numprocs);
MPI_Comm_rank (MPI_COMM_WORLD, &myid);
/*
Each MPI task performs the dot product, obtains its partial sum, and then
calls
MPI_Reduce to obtain the global sum.
*/
if (myid == 0)
printf("Starting omp_dotprod_mpi. Using %d tasks...\n",numprocs);
free (a);
free (b);
MPI_Finalize();
}
=========================================
/*****************************************************************************
* FILE: omp_dotprod_hybrid.c
* DESCRIPTION:
* This simple program is the hybrid version of a dot product and the fourth
* of four codes used to show the progression from a serial program to a
* hybrid MPI/OpenMP program. The relevant codes are:
* - omp_dotprod_serial.c - Serial version
* - omp_dotprod_openmp.c - OpenMP only version
SECRETARÍA DE EDUCACIÓN PÚBLICA
TECNOLÓGICO NACIONAL DE MÉXICO
INSTITUTO TECNOLÓGICO DE CIUDAD MADERO
* - omp_dotprod_mpi.c - MPI only version
* - omp_dotprod_hybrid.c - Hybrid MPI and OpenMP version
* SOURCE: Blaise Barney
* LAST REVISED: 06/02/17 Blaise Barney
******************************************************************************/
#include <mpi.h>
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
/* MPI Initialization */
MPI_Init (&argc, &argv);
MPI_Comm_size (MPI_COMM_WORLD, &numprocs);
MPI_Comm_rank (MPI_COMM_WORLD, &myid);
/*
Each MPI task uses OpenMP to perform the dot product, obtains its partial sum,
and then calls MPI_Reduce to obtain the global sum.
*/
if (myid == 0)
printf("Starting omp_dotprod_hybrid. Using %d tasks...\n",numprocs);
/*
Perform the dot product in an OpenMP parallel region for loop with a sum
reduction
For illustration purposes:
- Explicitly sets number of threads
- Gets and prints number of threads used
- Each thread keeps track of its partial sum
*/
free (a);
free (b);
MPI_Finalize();
}
Haga una tabla comparativa de los tiempos de ejecución entre los tiempos de ejecución, recuerde usar muchos datos.