Commit f25189ff authored by petros.anastasiadis's avatar petros.anastasiadis

Update 25/09/2017

parent b884aedf
......@@ -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" ;
......
......@@ -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" ;
......
......@@ -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);
......
......@@ -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<n ; ++i){
for ( j=0 ; j<m ; ++j) M[i*m+j]=0.0;
//printf( "Initialize data Thread=%d i=%d\n", omp_get_thread_num(), i);
......@@ -58,8 +57,8 @@ int main(int argc, char **argv)
vec_init(y, n, 0.0);
/* OpenMP Kernel */
printf("OpenMP Version(N=%d, M=%d, Threads=%s): ", n, m, getenv("OMP_NUM_THREADS"));
/* OpenMP Affinity Kernel */
printf("OpenMP_aff Version(N=%d, M=%d, Threads=%s): ", n, m, getenv("OMP_NUM_THREADS"));
timer = csecond();
for (i = 0; i < NR_ITER; ++i){
register double yi = 0;
......@@ -72,13 +71,16 @@ int main(int argc, char **argv)
}
}
timer = csecond() - timer;
#ifdef _DEBUG_ /* Output y in a file for debug purposes */
FILE * fp;
char * filename = "/users/guest/petyros/Training/Outputs/Debug/OpenMP_aff.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) ;
#ifdef _DEBUG_
/* Output y vector to a file for debugging */
FILE * fp;
char * filename = "/users/guest/petyros/Training/Outputs/Debug/OpenMP_aff.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);
return 0;
......
......@@ -20,22 +20,22 @@ int main(int argc, char **argv)
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");
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<n ; ++i) M[i] = (double *) calloc(m, sizeof(double));
if( !y || !x || !M ) error("memory allocation failed");
......@@ -62,13 +62,16 @@ int main(int argc, char **argv)
}
}
timer = csecond() - timer ;
#ifdef _DEBUG_
FILE * fp;
char * filename = "/users/guest/petyros/Training/Outputs/Debug/Serial.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/Serial.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);
return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment