/****************************************************************************** * FILE: omp_mm.c * DESCRIPTION: * OpenMp Example - Matrix Multiply - C Version * Demonstrates a matrix multiply using OpenMP. Threads share row iterations * according to a predefined chunk size. * AUTHOR: Blaise Barney * LAST REVISED: 06/28/05 ******************************************************************************/ /** * This program performs the multiplication of two matrix's. * Online source: * https://computing.llnl.gov/tutorials/openMP/samples/C/omp_mm.c **/ #include #include #include #ifdef _CIVL $input int NRA=5; /* number of rows in matrix A */ $input int NCA=5; /* number of columns in matrix A */ $input int NCB=5; /* number of columns in matrix B */ #else #define NRA 8 /* number of rows in matrix A */ #define NCA 8 /* number of columns in matrix A */ #define NCB 8 /* number of columns in matrix B */ #endif int main (int argc, char *argv[]) { int tid, nthreads, i, j, k, chunk; double a[NRA][NCA], /* matrix A to be multiplied */ b[NCA][NCB], /* matrix B to be multiplied */ c[NRA][NCB]; /* result matrix C */ chunk = 10; /* set loop iteration chunk size */ /*** Spawn a parallel region explicitly scoping all variables ***/ #pragma omp parallel shared(a,b,c,chunk) private(tid,i,j,k,nthreads) { tid = omp_get_thread_num(); if (tid == 0) { nthreads = omp_get_num_threads(); printf("Starting matrix multiple example with %d threads\n",nthreads); printf("Initializing matrices...\n"); } /*** Initialize matrices ***/ #pragma omp for schedule (static, chunk) for (i=0; i