<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 <mike.jackson@bluequartz.net><br><b><span style="font-weight: bold;">To:</span></b> Kaveh Kohan <kaveh.kohan@yahoo.com><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 <a ymailto="mailto:mike.jackson@bluequartz.net" href="mailto:mike.jackson@bluequartz.net">mike.jackson@bluequartz.net</a><br>BlueQuartz Software <a target="_blank" href="http://www.bluequartz.net">www.bluequartz.net</a><br>Principal Software Engineer Dayton, Ohio<br><br><br><br>On Jan 22, 2009, at 8:33 PM, Kaveh Kohan wrote:<br><br>> 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>> <a href="https://computing.llnl.gov/tutorials/openMP/exercise.html" target="_blank">https://computing.llnl.gov/tutorials/openMP/exercise.html</a><br>> <br>> and specifically this:<br>> 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>> /******************************************************************************<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>> <br>> _______________________________________________<br>> CMake mailing list<br>> <a ymailto="mailto:CMake@cmake.org" href="mailto:CMake@cmake.org">CMake@cmake.org</a><br>> <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>