<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>Many thanks and sorry for my naive question.</div><div style="font-family: times new roman,new york,times,serif; font-size: 14pt;"><br><div style="font-family: arial,helvetica,sans-serif; font-size: 13px;"><font size="2" face="Tahoma"><hr size="1"><b><span style="font-weight: bold;">From:</span></b> Michael Jackson &lt;mike.jackson@bluequartz.net&gt;<br><b><span style="font-weight: bold;">To:</span></b> Kaveh Kohan &lt;kaveh.kohan@yahoo.com&gt;<br><b><span style="font-weight: bold;">Cc:</span></b> cmake@cmake.org<br><b><span style="font-weight: bold;">Sent:</span></b> Thursday, January 22, 2009 8:59:27 PM<br><b><span style="font-weight: bold;">Subject:</span></b> Re: [CMake] PLEASE HELP: about openmp and cmake !!!!<br></font><br>
You need to also set the CMAKE_CXX_FLAGS and CMAKE_C_FLAGS using ccmake or your CMakeLists.txt file.<br><br><br>_________________________________________________________<br>Mike Jackson&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a ymailto="mailto:mike.jackson@bluequartz.net" href="mailto:mike.jackson@bluequartz.net">mike.jackson@bluequartz.net</a><br>BlueQuartz Software&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a target="_blank" href="http://www.bluequartz.net">www.bluequartz.net</a><br>Principal Software Engineer&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Dayton, Ohio<br><br><br><br>On Jan 22, 2009, at 8:33 PM, Kaveh Kohan wrote:<br><br>&gt; Hi everybody,<br>&gt; <br>&gt; I have a problem with CMAKE and I would be very appreciated if anybody can help.<br>&gt; <br>&gt; Basically, I am trying to compile very simple piece of multi-threaded code with CMAKE. I downloaded the code
 from:<br>&gt; <br>&gt; <a href="https://computing.llnl.gov/tutorials/openMP/exercise.html" target="_blank">https://computing.llnl.gov/tutorials/openMP/exercise.html</a><br>&gt; <br>&gt; and specifically this:<br>&gt; from: <a href="https://computing.llnl.gov/tutorials/openMP/samples/C/omp_mm.c" target="_blank">https://computing.llnl.gov/tutorials/openMP/samples/C/omp_mm.c</a><br>&gt; /******************************************************************************<br>&gt; * FILE: omp_mm.c<br>&gt; * DESCRIPTION:<br>&gt; *&nbsp;  OpenMp Example - Matrix Multiply - C Version<br>&gt; *&nbsp;  Demonstrates a matrix multiply using OpenMP. Threads share row iterations<br>&gt; *&nbsp;  according to a predefined chunk size.<br>&gt; * AUTHOR: Blaise Barney<br>&gt; * LAST REVISED: 06/28/05<br>&gt; ******************************************************************************/<br>&gt; #include &lt;omp.h&gt;<br>&gt; #include &lt;stdio.h&gt;<br>&gt; #include
 &lt;stdlib.h&gt;<br>&gt; <br>&gt; #define NRA 62&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  /* number of rows in matrix A */<br>&gt; #define NCA 15&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  /* number of columns in matrix A */<br>&gt; #define NCB 7&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* number of columns in matrix B */<br>&gt; <br>&gt; int main (int argc, char *argv[])<br>&gt; {<br>&gt; int&nbsp; &nbsp; tid, nthreads, i, j, k, chunk;<br>&gt; double&nbsp; &nbsp; a[NRA][NCA],&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  /* matrix A to be multiplied */<br>&gt;&nbsp; &nbsp;  b[NCA][NCB],&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  /* matrix B to be multiplied */<br>&gt;&nbsp; &nbsp;  c[NRA][NCB];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  /* result matrix C */<br>&gt; <br>&gt; chunk = 10;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* set loop iteration chunk size */<br>&gt; <br>&gt; /*** Spawn a parallel
 region explicitly scoping all variables ***/<br>&gt; #pragma omp parallel shared(a,b,c,nthreads,chunk) private(tid,i,j,k)<br>&gt;&nbsp;  {<br>&gt;&nbsp;  tid = omp_get_thread_num();<br>&gt;&nbsp;  if (tid == 0)<br>&gt;&nbsp; &nbsp;  {<br>&gt;&nbsp; &nbsp;  nthreads = omp_get_num_threads();<br>&gt;&nbsp; &nbsp;  printf("Starting matrix multiple example with %d threads\n",nthreads);<br>&gt;&nbsp; &nbsp;  printf("Initializing matrices...\n");<br>&gt;&nbsp; &nbsp;  }<br>&gt;&nbsp;  /*** Initialize matrices ***/<br>&gt;&nbsp;  #pragma omp for schedule (static, chunk)<br>&gt;&nbsp;  for (i=0; i&lt;NRA; i++)<br>&gt;&nbsp; &nbsp;  for (j=0; j&lt;NCA; j++)<br>&gt;&nbsp; &nbsp; &nbsp;  a[i][j]= i+j;<br>&gt;&nbsp;  #pragma omp for schedule (static, chunk)<br>&gt;&nbsp;  for (i=0; i&lt;NCA; i++)<br>&gt;&nbsp; &nbsp;  for (j=0; j&lt;NCB; j++)<br>&gt;&nbsp; &nbsp; &nbsp;  b[i][j]= i*j;<br>&gt;&nbsp;  #pragma omp for schedule (static, chunk)<br>&gt;&nbsp;  for (i=0;
 i&lt;NRA; i++)<br>&gt;&nbsp; &nbsp;  for (j=0; j&lt;NCB; j++)<br>&gt;&nbsp; &nbsp; &nbsp;  c[i][j]= 0;<br>&gt; <br>&gt;&nbsp;  /*** Do matrix multiply sharing iterations on outer loop ***/<br>&gt;&nbsp;  /*** Display who does which iterations for demonstration purposes ***/<br>&gt;&nbsp;  printf("Thread %d starting matrix multiply...\n",tid);<br>&gt;&nbsp;  #pragma omp for schedule (static, chunk)<br>&gt;&nbsp;  for (i=0; i&lt;NRA; i++)<br>&gt;&nbsp; &nbsp;  {<br>&gt;&nbsp; &nbsp;  printf("Thread=%d did row=%d\n",tid,i);<br>&gt;&nbsp; &nbsp;  for(j=0; j&lt;NCB; j++)<br>&gt;&nbsp; &nbsp; &nbsp;  for (k=0; k&lt;NCA; k++)<br>&gt;&nbsp; &nbsp; &nbsp; &nbsp;  c[i][j] += a[i][k] * b[k][j];<br>&gt;&nbsp; &nbsp;  }<br>&gt;&nbsp;  }&nbsp;  /*** End of parallel region ***/<br>&gt; <br>&gt; /*** Print results ***/<br>&gt; printf("******************************************************\n");<br>&gt; printf("Result Matrix:\n");<br>&gt; for (i=0; i&lt;NRA;
 i++)<br>&gt;&nbsp;  {<br>&gt;&nbsp;  for (j=0; j&lt;NCB; j++)<br>&gt;&nbsp; &nbsp;  printf("%6.2f&nbsp;  ", c[i][j]);<br>&gt;&nbsp;  printf("\n");<br>&gt;&nbsp;  }<br>&gt; printf("******************************************************\n");<br>&gt; printf ("Done.\n");<br>&gt; <br>&gt; }<br>&gt; <br>&gt; Here is the CMakefile I use:<br>&gt; <br>&gt; PROJECT(omp_mm)<br>&gt; <br>&gt; SET(CurrentExe "omp_mm")<br>&gt; ADD_EXECUTABLE(${CurrentExe} omp_mm.c )<br>&gt; <br>&gt; and I change:<br>&gt; CMAKE_EXE_LINKER_FLAGS : -fopenmp<br>&gt; <br>&gt; "Seemingly", it compiles&nbsp; correctly:<br>&gt; make<br>&gt; Linking C executable omp_mm<br>&gt; [100%] Built target omp_mm<br>&gt; <br>&gt; but it seems that it ignores #pragma and no matter how I set $OMP_NUM_THREADS, it always lunch one thread.<br>&gt; <br>&gt; ""Surprisingly"", when&nbsp; I compiled it on the command line by:<br>&gt; &gt;&gt; g++&nbsp; omp_mm.c&nbsp; -o omp_mm -fopenmp<br>&gt; <br>&gt; it
 compiles and "works" perfectly and lunch as many threads as I set it $OMP_NUM_THREADS.<br>&gt; <br>&gt; I am quite frustrated, Makefile generated by cmake is not easy to edit.&nbsp; Here is my Cmake and gcc information, in case it is required:<br>&gt; <br>&gt; cmake version 2.6-patch 2<br>&gt;&nbsp; &gt;&gt; gcc -v<br>&gt; Using built-in specs.<br>&gt; Target: x86_64-linux-gnu<br>&gt; 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>&gt; Thread
 model: posix<br>&gt; gcc version 4.3.2 (Ubuntu 4.3.2-1ubuntu11)<br>&gt; <br>&gt; <br>&gt; <br>&gt; I would be thankful if you could help.<br>&gt; <br>&gt; <br>&gt; Regards,<br>&gt; Kaveh<br>&gt; <br>&gt; <br>&gt; <br>&gt; _______________________________________________<br>&gt; CMake mailing list<br>&gt; <a ymailto="mailto:CMake@cmake.org" href="mailto:CMake@cmake.org">CMake@cmake.org</a><br>&gt; <a href="http://www.cmake.org/mailman/listinfo/cmake" target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a><br><br></div></div></div><br>

      </body></html>