openmp

openmp conditional parallel loop

China☆狼群 提交于 2019-12-04 03:16:49
问题 I am trying to use an openmp for loop if a certain condition holds. I could simply use an if else statement to use the parallel for loop if a condition holds, but the code in the for loop is a bit long and it would double the length of the code if I just use the if else statement. So basically, I want a better way to do this: if(condition_holds){ // use parallel for loop #pragma omp parallel for for(...){ // Long piece of code } }else{ // Don't use parallel for loop for(...){ // Long piece of

OpenMP thread mapping to physical cores

吃可爱长大的小学妹 提交于 2019-12-04 02:42:27
问题 So I've looked around online for some time to no avail. I'm new to using OpenMP and so not sure of the terminology here, but is there a way to figure out a specific machine's mapping from OMPThread (given by omp_get_thread_num();) and the physical cores on which the threads will run? Also I was interested in how exactly OMP assigned threads, for example is thread 0 always going to run in the same location when the same code is run on the same machine? Thanks. 回答1: Typically, the OS takes care

Optimising and why openmp is much slower than sequential way?

纵然是瞬间 提交于 2019-12-04 02:03:29
I am a newbie in programming with OpenMp. I wrote a simple c program to multiply matrix with a vector. Unfortunately, by comparing executing time I found that the OpenMP is much slower than the Sequential way. Here is my code (Here the matrix is N*N int, vector is N int, result is N long long): #pragma omp parallel for private(i,j) shared(matrix,vector,result,m_size) for(i=0;i<m_size;i++) { for(j=0;j<m_size;j++) { result[i]+=matrix[i][j]*vector[j]; } } And this is the code for sequential way: for (i=0;i<m_size;i++) for(j=0;j<m_size;j++) result[i] += matrix[i][j] * vector[j]; When I tried these

c++: OpenMP and non-random-access STL containers - a possible workaround

拟墨画扇 提交于 2019-12-04 01:54:32
So on SO, and the Internets in general, there is much confusion and frustration about how to make OpenMP's easy-to-use #pragma directives cooperate with C++'s equally easy-to-use STL containers. Everyone talks about work-arounds for STL vector , but what about non-random access / bi-directional containers, like map , list , set , etc. ? I encountered this problem and devised a very simple, obvious workaround. I present it here for STL map , but it is clearly generalizable. Serial version: for (std::map<A,B>::iterator it = my_map.begin(); it != my_map.end(); ++it) { /* do work with it */ } My

apple clang -fopenmp not working

匆匆过客 提交于 2019-12-04 00:24:38
问题 I am trying to use openmp with Apple clang but can't make it work. I did download and compile the openmp library from llvm. My problem is that clang doesn't recognize the -fopenmp flag. I get the following error: clang: error: unsupported option '-fopenmp' I have version 8 of Xcode and clang. Any help would be much appreciated. 回答1: From what I learned so far is that clang that comes with xcode does not support openmp. Also, the versions are different. So clang that comes with xcode 8 has

CMake cannot find OpenMP

微笑、不失礼 提交于 2019-12-03 23:36:59
I am trying to compile with OpenMP. My CMakeLists.txt contains the line find_package(OpenMP REQUIRED) and CMake errors out with CMake Error at /opt/ros/groovy/share/catkin/cmake/catkinConfig.cmake:72 (find_package): Could not find a configuration file for package openmp. Set openmp_DIR to the directory containing a CMake configuration file for openmp. The file will have one of the following names: openmpConfig.cmake openmp-config.cmake Checking my filesystem, I see that I have /usr/share/cmake-2.8/Modules/FindOpenMP.cmake but no openmpConfig.cmake or openmp-config.cmake . What do I need to do

OpenMP while loop

荒凉一梦 提交于 2019-12-03 22:30:34
问题 I have a code that runs many iterations and only if a condition is met, the result of the iteration is saved. This is naturally expressed as a while loop. I am attempting to make the code run in parallel, since each realisation is independent. So I have this: while(nit<avit){ #pragma omp parallel shared(nit,avit) { //do some stuff if(condition){ #pragma omp critical { nit++; \\save results } } }//implicit barrier here } and this works fine... but there is a barrier after each realization,

All OpenMP Tasks running on the same thread

余生长醉 提交于 2019-12-03 21:35:38
问题 I have wrote a recursive parallel function using tasks in OpenMP. While it gives me the correct answer and runs fine I think there is an issue with the parallelism.The run-time in comparison with a serial solution does not scale in the same other parallel problem I have solved without tasks have. When printing each thread for the tasks they are all running on thread 0. I am compiling and running on Visual Studio Express 2013. int parallelOMP(int n) { int a, b, sum = 0; int alpha = 0, beta = 0

OpenMP: how to flush pointer target?

丶灬走出姿态 提交于 2019-12-03 21:21:29
I’ve just noticed that the following code doesn’t compile in OpenMP (under GCC 4.5.1): struct job { unsigned busy_children; }; job* j = allocateJob(…); // … #pragma omp flush(j->busy_children) The compiler complains about the -> in the argument list to flush, and according to the OpenMP specification it’s right: flush expects as arguments a list of “id-expression”s, which basically means only (qualified) IDs are allowed, no expressions. Furthermore, the spec says this about flush and pointers: If a pointer is present in the list, the pointer itself is flushed, not the memory block to which the

The differences in the accuracy of the calculations in single / multi-threaded (OpenMP) modes

十年热恋 提交于 2019-12-03 20:25:52
Can anybody explain/understand the different of the calculation result in single / multi-threaded mode? Here is an example of approx. calculation of pi: #include <iomanip> #include <cmath> #include <ppl.h> const int itera(1000000000); int main() { printf("PI calculation \nconst int itera = 1000000000\n\n"); clock_t start, stop; //Single thread start = clock(); double summ_single(0); for (int n = 1; n < itera; n++) { summ_single += 6.0 / (static_cast<double>(n)* static_cast<double>(n)); }; stop = clock(); printf("Time single thread %f\n", (double)(stop - start) / 1000.0); //Multithread with OMP