diff --git a/MPI/MPI-OpenMP.c b/MPI/MPI-OpenMP.c index 698e270a80ead79d38857589932b7660926da497..5fdfb6aea96f4e3fc6f5f663846cec71697a9cb5 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 acafc497348aae8bc6514d1ac68840ed457e9db1..91333a239f7e8480fc9f0f310ffcf8d88c085441 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 d4311e11162498eb0dfc36de7c2998b7acfba05a..964c7617a63e389cba16f154a5efad3233aeaefd 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 e25d9bf3a9e16b003bc629030448b06c977d448a..a5dd2648c99762224c759f5428b3ed735f4cb392 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