<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman,new york,times,serif;font-size:14pt"><div>Hi everybody,<br><br>I have a problem with CMAKE and I would be very appreciated if anybody can help.<br><br>Basically, I am trying to compile very simple piece of multi-threaded code with CMAKE. I downloaded the code from:<br><br>https://computing.llnl.gov/tutorials/openMP/exercise.html<br><br>and specifically this:<br>from: https://computing.llnl.gov/tutorials/openMP/samples/C/omp_mm.c <br>/******************************************************************************<br>
* FILE: omp_mm.c<br>
* DESCRIPTION: <br>
* OpenMp Example - Matrix Multiply - C Version<br>
* Demonstrates a matrix multiply using OpenMP. Threads share row iterations<br>
* according to a predefined chunk size.<br>
* AUTHOR: Blaise Barney<br>
* LAST REVISED: 06/28/05<br>
******************************************************************************/<br>
#include <omp.h><br>
#include <stdio.h><br>
#include <stdlib.h><br>
<br>
#define NRA 62 /* number of rows in matrix A */<br>
#define NCA 15 /* number of columns in matrix A */<br>
#define NCB 7 /* number of columns in matrix B */<br>
<br>
int main (int argc, char *argv[]) <br>
{<br>
int tid, nthreads, i, j, k, chunk;<br>
double a[NRA][NCA], /* matrix A to be multiplied */<br>
b[NCA][NCB], /* matrix B to be multiplied */<br>
c[NRA][NCB]; /* result matrix C */<br>
<br>
chunk = 10; /* set loop iteration chunk size */<br>
<br>
/*** Spawn a parallel region explicitly scoping all variables ***/<br>
#pragma omp parallel shared(a,b,c,nthreads,chunk) private(tid,i,j,k)<br>
{<br>
tid = omp_get_thread_num();<br>
if (tid == 0)<br>
{<br>
nthreads = omp_get_num_threads();<br>
printf("Starting matrix multiple example with %d threads\n",nthreads);<br>
printf("Initializing matrices...\n");<br>
}<br>
/*** Initialize matrices ***/<br>
#pragma omp for schedule (static, chunk) <br>
for (i=0; i<NRA; i++)<br>
for (j=0; j<NCA; j++)<br>
a[i][j]= i+j;<br>
#pragma omp for schedule (static, chunk)<br>
for (i=0; i<NCA; i++)<br>
for (j=0; j<NCB; j++)<br>
b[i][j]= i*j;<br>
#pragma omp for schedule (static, chunk)<br>
for (i=0; i<NRA; i++)<br>
for (j=0; j<NCB; j++)<br>
c[i][j]= 0;<br>
<br>
/*** Do matrix multiply sharing iterations on outer loop ***/<br>
/*** Display who does which iterations for demonstration purposes ***/<br>
printf("Thread %d starting matrix multiply...\n",tid);<br>
#pragma omp for schedule (static, chunk)<br>
for (i=0; i<NRA; i++) <br>
{<br>
printf("Thread=%d did row=%d\n",tid,i);<br>
for(j=0; j<NCB; j++) <br>
for (k=0; k<NCA; k++)<br>
c[i][j] += a[i][k] * b[k][j];<br>
}<br>
} /*** End of parallel region ***/<br>
<br>
/*** Print results ***/<br>
printf("******************************************************\n");<br>
printf("Result Matrix:\n");<br>
for (i=0; i<NRA; i++)<br>
{<br>
for (j=0; j<NCB; j++) <br>
printf("%6.2f ", c[i][j]);<br>
printf("\n"); <br>
}<br>
printf("******************************************************\n");<br>
printf ("Done.\n");<br>
<br>
}<br><br>Here is the CMakefile I use:<br><br>PROJECT(omp_mm)<br><br>SET(CurrentExe "omp_mm")<br>ADD_EXECUTABLE(${CurrentExe} omp_mm.c ) <br><br>and I change:<br>CMAKE_EXE_LINKER_FLAGS : -fopenmp<br><br>"Seemingly", it compiles correctly:<br>make<br>Linking C executable omp_mm<br>[100%] Built target omp_mm<br><br>but it seems that it ignores #pragma and no matter how I set $OMP_NUM_THREADS, it always lunch one thread.<br><br>""Surprisingly"", when I compiled it on the command line by:<br>>> g++ omp_mm.c -o omp_mm -fopenmp<br><br>it compiles and "works" perfectly and lunch as many threads as I set it $OMP_NUM_THREADS.<br><br>I am quite frustrated, Makefile generated by cmake is not easy to edit. Here is my Cmake and gcc information, in case it is required:<br><br>cmake version 2.6-patch 2<br> >> gcc -v<br>Using built-in specs.<br>Target: x86_64-linux-gnu<br>Configured with: ../src/configure -v
--with-pkgversion='Ubuntu 4.3.2-1ubuntu11' --with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu<br>Thread model: posix<br>gcc version 4.3.2 (Ubuntu 4.3.2-1ubuntu11) <br><br><br><br>I would be thankful if you could help.<br><br><br>Regards,<br>Kaveh <br><br><br></div></div><br>
</body></html>