From f25189ff96bd924274f2f6f3eda0fdfd40460b00 Mon Sep 17 00:00:00 2001
From: "petros.anastasiadis"
Date: Mon, 25 Sep 2017 15:14:07 +0300
Subject: [PATCH] Update 25/09/2017
---
MPI/MPI-OpenMP.c | 22 +++++++++-------------
MPI/MPI.c | 22 +++++++++-------------
OpenMP/OpenMP.c | 20 +++++++++++---------
OpenMP/OpenMP_aff.c | 28 +++++++++++++++-------------
Serial/Serial.c | 25 ++++++++++++++-----------
5 files changed, 58 insertions(+), 59 deletions(-)
diff --git a/MPI/MPI-OpenMP.c b/MPI/MPI-OpenMP.c
index 698e270..5fdfb6a 100644
--- a/MPI/MPI-OpenMP.c
+++ b/MPI/MPI-OpenMP.c
@@ -12,29 +12,26 @@ int main(int argc, char ** argv) {
int global_nm[2],local_nm[2]; //global matrix dimensions and local matrix dimensions (2D-domain, 2D-subdomain)
int global_padded_nm[2]; //padded global matrix dimensions (if padding is not needed, global_padded=global)
int i,j,k, sparse=0, *cooCol, n_z, *I;
- MPI_Datatype dummy; //dummy datatype used to align user-defined datatypes in memory
-
- double * M, * A, * x, * y, *local_y, * cooVal, comm_t, comp_t; //Global matrix, local current and previous matrices, pointer to swap between current and previous
+ double * M, * A, * x, * y, *local_y, * cooVal, comm_t, comp_t;
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD,&size);
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
- /* Read n,m from stdin */
if (argc < 2) error("Too few Arguments");
- else if ( argc == 2) /* ./Program Input_File */
+ else if ( argc == 2) /* ./Program Input_File -> File Input to COO */
{
if(!mtx_read(&I, &cooCol, &cooVal, &global_nm[0], &global_nm[1], &n_z, argv[1])) error("input and/or COO convertion failed");
sparse = 1;
}
- else if ( argc == 3) { /*./Program N M */
+ else if ( argc == 3) { /*./Program N M -> Generate random NxM matrix */
global_nm[0]=atoi(argv[1]);
global_nm[1]=atoi(argv[2]);
}
else error("Too many Arguments");
- /* Padd n if needed */
+ /* Padd N if needed */
local_nm[1]=global_nm[1];
global_padded_nm[1]=global_nm[1];
@@ -76,8 +73,7 @@ int main(int argc, char ** argv) {
//printf( "Initialize data Thread=%d i=%d\n", omp_get_thread_num(), i);
}
- //----Rank 0 scatters the global matrix----//
-
+ /* Rank 0 scatters the global matrix */
double * gsendbuf;
if (rank == 0){
gsendbuf = &(M[0]);
@@ -103,14 +99,14 @@ int main(int argc, char ** argv) {
local_y[k] = yi;
}
}
+
MPI_Barrier(MPI_COMM_WORLD);
if (rank==0) comp_t= MPI_Wtime() - comp_t;
-
MPI_Gather(local_y, local_nm[0], MPI_DOUBLE, y, local_nm[0], MPI_DOUBLE, 0, MPI_COMM_WORLD);
- //MPI_Reduce(local_y, y, global_nm[0], MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
-
if (rank==0) comm_t = MPI_Wtime() - comm_t - comp_t;
-#ifdef _DEBUG_ /* Output y in a file for debug purposes */
+
+#ifdef _DEBUG_
+ /* Output y vector to a file for debugging */
if (rank == 0) {
FILE * fp;
char * filename = "/users/guest/petyros/Training/Outputs/Debug/MPI-OpenMP.out" ;
diff --git a/MPI/MPI.c b/MPI/MPI.c
index acafc49..91333a2 100644
--- a/MPI/MPI.c
+++ b/MPI/MPI.c
@@ -12,29 +12,26 @@ int main(int argc, char ** argv) {
int global_nm[2],local_nm[2]; //global matrix dimensions and local matrix dimensions (2D-domain, 2D-subdomain)
int global_padded_nm[2]; //padded global matrix dimensions (if padding is not needed, global_padded=global)
int i,j,k, sparse=0, *cooCol, n_z, *I;
- MPI_Datatype dummy; //dummy datatype used to align user-defined datatypes in memory
-
- double * M, * A, * x, * y, *local_y, * cooVal, comm_t, comp_t; //Global matrix, local current and previous matrices, pointer to swap between current and previous
+ double * M, * A, * x, * y, *local_y, * cooVal, comm_t, comp_t;
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD,&size);
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
- /* Read n,m from stdin */
if (argc < 2) error("Too few Arguments");
- else if ( argc == 2) /* ./Program Input_File */
+ else if ( argc == 2) /* ./Program Input_File -> File Input to COO */
{
if(!mtx_read(&I, &cooCol, &cooVal, &global_nm[0], &global_nm[1], &n_z, argv[1])) error("input and/or COO convertion failed");
sparse = 1;
}
- else if ( argc == 3) { /*./Program N M */
+ else if ( argc == 3) { /*./Program N M -> Generate random NxM matrix */
global_nm[0]=atoi(argv[1]);
global_nm[1]=atoi(argv[2]);
}
else error("Too many Arguments");
- /* Padd n if needed */
+ /* Padd N if needed */
local_nm[1]=global_nm[1];
global_padded_nm[1]=global_nm[1];
@@ -70,8 +67,7 @@ int main(int argc, char ** argv) {
A = (double *) malloc(local_nm[0] * local_nm[1] * sizeof(*M));
- //----Rank 0 scatters the global matrix----//
-
+ /* Rank 0 scatters the global matrix */
double * gsendbuf;
if (rank == 0){
gsendbuf = &(M[0]);
@@ -96,14 +92,14 @@ int main(int argc, char ** argv) {
local_y[k] = yi;
}
}
+
MPI_Barrier(MPI_COMM_WORLD);
if (rank==0) comp_t= MPI_Wtime() - comp_t;
-
MPI_Gather(local_y, local_nm[0], MPI_DOUBLE, y, local_nm[0], MPI_DOUBLE, 0, MPI_COMM_WORLD);
- //MPI_Reduce(local_y, y, global_nm[0], MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
-
if (rank==0) comm_t = MPI_Wtime() - comm_t - comp_t;
-#ifdef _DEBUG_ /* Output y in a file for debug purposes */
+
+#ifdef _DEBUG_
+ /* Output y vector to a file for debugging */
if (rank == 0) {
FILE * fp;
char * filename = "/users/guest/petyros/Training/Outputs/Debug/MPI.out" ;
diff --git a/OpenMP/OpenMP.c b/OpenMP/OpenMP.c
index d4311e1..964c761 100644
--- a/OpenMP/OpenMP.c
+++ b/OpenMP/OpenMP.c
@@ -21,20 +21,19 @@ int main(int argc, char **argv)
int *I, *cooCol, n_z, sparse=0;
double *cooVal, timer;
-
- /* File Input to COO */
if (argc < 2) error("Too few Arguments");
- else if ( argc == 2) /* ./Program Input_File */
+ else if ( argc == 2) /* ./Program Input_File -> File Input to COO */
{
if(!mtx_read(&I, &cooCol, &cooVal, &n, &m, &n_z, argv[1])) error("input and/or COO convertion failed");
sparse = 1;
}
- else if ( argc == 3) { /*./Program N M */
+ else if ( argc == 3) { /*./Program N M -> Generate random NxM matrix */
n = atoi(argv[1]);
m = atoi(argv[2]);
}
else error("Too many Arguments");
+ /* Allocate space */
double *x = (double *) malloc(m * sizeof(*x));
double *y = (double *) malloc(n * sizeof(*y));
double **M = (double **) malloc(n * sizeof(*M));
@@ -65,13 +64,16 @@ int main(int argc, char **argv)
}
}
timer = csecond() - timer;
+
#ifdef _DEBUG_
- FILE * fp;
- char * filename = "/users/guest/petyros/Training/Outputs/Debug/OpenMP.out" ;
- if(( fp = fopen( filename, "w")) == NULL) error("Output file creation failed\n");
- for (k = 0; k < n; ++k) fprintf(fp, "%lf ", y[k]) ;
- fclose(fp) ;
+ /* Output y vector to a file for debugging */
+ FILE * fp;
+ char * filename = "/users/guest/petyros/Training/Outputs/Debug/OpenMP.out" ;
+ if(( fp = fopen( filename, "w")) == NULL) error("Output file creation failed\n");
+ for (k = 0; k < n; ++k) fprintf(fp, "%lf ", y[k]) ;
+ fclose(fp) ;
#endif
+
report_results(timer);
diff --git a/OpenMP/OpenMP_aff.c b/OpenMP/OpenMP_aff.c
index e25d9bf..a5dd264 100644
--- a/OpenMP/OpenMP_aff.c
+++ b/OpenMP/OpenMP_aff.c
@@ -20,25 +20,24 @@ int main(int argc, char **argv)
int *I, *cooCol, n_z, sparse=0;
double *cooVal, timer;
-
- /* File Input to COO */
if (argc < 2) error("Too few Arguments");
- else if ( argc == 2) /* ./Program Input_File */
+ else if ( argc == 2) /* ./Program Input_File -> File Input to COO */
{
if(!mtx_read(&I, &cooCol, &cooVal, &n, &m, &n_z, argv[1])) error("input and/or COO convertion failed");
sparse = 1;
}
- else if ( argc == 3) { /*./Program N M */
+ else if ( argc == 3) { /*./Program N M -> Generate random NxM matrix */
n = atoi(argv[1]);
m = atoi(argv[2]);
}
else error("Too many Arguments");
+ /* Allocate space */
double *x = (double *) malloc(m * sizeof(*x));
double *y = (double *) malloc(n * sizeof(*y));
double *M = (double *) malloc(n * m * sizeof(*M));
- #pragma omp parallel for schedule(static) /* Initialize data for each thread in corresponding socket with first-touch policy */
+ #pragma omp parallel for schedule(static) /* Initialize data for each thread in corresponding socket/cache with first-touch policy */
for( i=0 ; i File Input to COO */
{
if(!mtx_read(&I, &cooCol, &cooVal, &n, &m, &n_z, argv[1])) error("input and/or COO convertion failed");
sparse = 1;
}
- else if ( argc == 3) { /*./Program N M */
+ else if ( argc == 3) { /*./Program N M -> Generate random NxM matrix */
n = atoi(argv[1]);
m = atoi(argv[2]);
}
else error("Too many Arguments");
-
- double *x = (double *) malloc(m * sizeof(*x));
+
+ /* Allocate space */
+ double *x = (double *) malloc(m * sizeof(*x));
double *y = (double *) malloc(n * sizeof(*y));
- double **M = (double **) malloc(n * sizeof(*M));
+ double **M = (double **) malloc(n * sizeof(*M));
for( i=0 ; i