0

I have used two different parallel programs one is normal parallel program in an openMP for Matrix multiplication and other one Nested parallel program in OpenMP The execution time in nested program where number of threads are increased are coming to be larger which should ideally be i think less My system is 12 cores

Nested code : #include

include

include

include

define N 1000

float A[N][N], B[N][N], C[N][N]; // declaring matrices of NxN size int main () { /* DECLARING VARIABLES / int i, j, m; // indices for matrix multiplication //float t_1; // Execution time measures //clock_t c_1, c_2; / FILLING MATRICES WITH RANDOM NUMBERS / srand ( time(NULL) ); for(i=0;i MATRIX MULTIPLICATION */ printf("Max number of threads: %i \n",omp_get_max_threads()); #pragma omp parallel omp_set_nested(1); //printf("Number of threads: %i \n",omp_get_num_threads()); clock_t c_1=time(NULL); // time measure: start mm //#pragma omp parallel for private(m,j) // #pragma omp_set_num_threads(8)

pragma omp parallel for schedule(dynamic,1) for(i=0;i

pragma omp parallel for schedule(dynamic,1) for(j=0;j

C=0 C[i][j]=0.; // set initial value of resulting matrix

pragma omp parallel for

for(m=0;mB[m][j]+C[i][j]; } printf("C: %f \n",C[i][j]); } } / TIME MEASURE + OUTPUT / clock_t c_2=time(NULL); // time measure: end mm float t_1 = (float)(c_2-c_1); // time elapsed for job row- wise printf("Execution time: %f \n",t_1); / TERMINATE PROGRAM */ return 0; }

Normal one : #include

include

include

define N 1000

float A[N][N], B[N][N], C[N][N]; // declaring matrices of NxN size int main () { /* DECLARING VARIABLES / int i, j, m; // indices for matrix multiplication float t_1; // Execution time measures clock_t c_1, c_2; / FILLING MATRICES WITH RANDOM NUMBERS */ srand ( time(NULL) ); for(i=0;i

/* MATRIX MULTIPLICATION */
printf("Max number of threads: %i \n",omp_get_max_threads());
pragma omp parallel
printf("Number of threads: %i \n",omp_get_num_threads());
c_1=time(NULL);  // time measure: start mm
pragma omp parallel for private(m,j)
// #pragma omp_set_num_threads(8)
for(i=0;i<N;i++) {
    for(j=0;j<N;j++) {
        // }
        C[i][j]=0.; // set initial value of resulting matrix C = 0
        for(m=0;m<N;m++) {
            C[i][j]=A[i][m]*B[m][j]+C[i][j];
        }
        printf("C: %f \n",C[i][j]);
    }
    /* TIME MEASURE + OUTPUT */
    c_2=time(NULL);  // time measure: end mm
    t_1 = (float)(c_2-c_1); // time elapsed for job row-wise
    printf("Execution time: %f \n",t_1);
    /* TERMINATE PROGRAM */
    return 0; } 

closed as off-topic by jasonwryan, GAD3R, Archemar, countermode, Stephen Kitt Jan 3 '17 at 7:49

  • This question does not appear to be about Unix or Linux within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

locked by Community Jan 3 '17 at 7:49