/******************************************************************** C-DAC Tech Workshop : hyPACK-2013 October 15-18, 2013 Example 1.10 : omp-workshare-section.c Objective : Write an OpenMP Program to illustrate Work-Sharing section. In this , the OpenMP SECTION directive is used to assign different operations to each thread that executes a SECTION. Input : a) Number of threads b) Size of matrices (numofrows and noofcols ) Output : Time taken by the parallel and serial computation Created : August-2013 E-mail : hpcfte@cdac.in ************************************************************************/ #include #include #include #include #include /* Main Program */ main(int argc,char **argv) { int NoofCols,NoofRows,index,VectorSize,icol,vec_col,irow,MatrixFileStatus=1,VectorFileStatus=1; int matrowsize,matcolsize,vectorsize; float **Matrix, **Matrix_one,*Vector, *Result_Vector; FILE *fp1; struct timeval TimeValue_Start, TimeValue1_Start; struct timezone TimeZone_Start, TimeZone1_Start; struct timeval TimeValue_Final, TimeValue1_Final; struct timezone TimeZone_Final, TimeZone1_Final; long time_start, time_end; double time_overhead1,time_overhead2; int icol1 ,irow1; printf("\n\t\t---------------------------------------------------------------------------"); printf("\n\t\t Centre for Development of Advanced Computing (C-DAC)"); printf("\n\t\t Email : hpcfte@cdac.in"); printf("\n\t\t---------------------------------------------------------------------------"); printf("\n\t\t Objective : OpenMP Work-Sharing Construct ."); printf("\n\t\t The OpenMP SECTION directive is used to assign different operations to each "); printf("\n\t\t thread that executes a SECTION."); printf("\n\t\t OpenMP Work-Shareing Construct : SECTION Directive . "); printf("\n\t\t..........................................................................\n"); if(argc != 4){ printf("\t\t Very Few Arguments\n "); printf("\t\t Syntax : exec \n"); exit(-1); } /* printf("\n\t\t Enter the No. of Rows and Columns of Matrix and Vector Size \n"); scanf("%d%d%d",&matrowsize,&matcolsize,&vectorsize); */ matrowsize = atoi(argv[1]); matcolsize = atoi(argv[2]); vectorsize = atoi(argv[3]); if( matcolsize != vectorsize) { printf("\n\n\t\t Matrix into vertor multiplication not possible "); printf("\n\t\t Vector Size != Matrix Col size \n"); exit(-1); } /* ....................................................................................... The OpenMP SECTION directive is used to assign different operations to each thread that executes a SECTION. - One thread will do the file operation - Second thread will do the matrix vector computation ........................................................................................*/ gettimeofday(&TimeValue_Start, &TimeZone_Start); omp_set_num_threads(2); #pragma omp parallel { #pragma omp sections { #pragma omp section { printf("\n\n\t\t %d - Thread is doing section 1 ", omp_get_thread_num()); if ((fp1 = fopen ("./data/mdata.inp", "r")) == NULL){ printf("\n\t\t Failed to open the file\n "); MatrixFileStatus = 0; } if(MatrixFileStatus != 0) { /* fscanf(fp1,"%d%d\n",&NoofRows,&NoofCols); Matrix = (float **)malloc(NoofRows*sizeof(float *)); for(irow=0 ;irow