openmp

Insertion Sort in OpenMP

こ雲淡風輕ζ 提交于 2019-12-18 08:58:10
问题 I'm trying to write OpenMP solution for Insertion sort but I'm having problems to make it run in parallel and give correct results :). Is there any way to make Insertion sort it run in parallel. Here is my code: void insertionsort(int *A, int num) { // clock_t start, stop; // // start=clock(); int k; #pragma omp parallel for shared(A) private(k) for(int n = 1; n < num; n++) { int key = A[n]; k = n; #pragma omp critical for(;k>0 && A[k-1]> key;k--) { A[k] = A[k-1]; } A[k] = key; } // stop

Insertion Sort in OpenMP

爱⌒轻易说出口 提交于 2019-12-18 08:58:07
问题 I'm trying to write OpenMP solution for Insertion sort but I'm having problems to make it run in parallel and give correct results :). Is there any way to make Insertion sort it run in parallel. Here is my code: void insertionsort(int *A, int num) { // clock_t start, stop; // // start=clock(); int k; #pragma omp parallel for shared(A) private(k) for(int n = 1; n < num; n++) { int key = A[n]; k = n; #pragma omp critical for(;k>0 && A[k-1]> key;k--) { A[k] = A[k-1]; } A[k] = key; } // stop

openmp - while loop for text file reading and using a pipeline

为君一笑 提交于 2019-12-18 03:04:27
问题 I discovered that openmp doesn't support while loops( or at least doesn't like them too much). And also doesn't like the ' != ' operator. I have this bit of code. int count = 1; #pragma omp parallel for while ( fgets(buff, BUFF_SIZE, f) != NULL ) { len = strlen(buff); int sequence_counter = segment_read(buff,len,count); if (sequence_counter == 1) { count_of_reads++; printf("\n Total No. of reads: %d \n",count_of_reads); } count++; } Any clues as to how to manage this ? I read somewhere (

OpenMP: poor performance of heap arrays (stack arrays work fine)

允我心安 提交于 2019-12-17 21:54:29
问题 I am a fairly experienced OpenMP user, but I have just run into a puzzling problem, and I am hopeful that someone here could help. The problem is that a simple hashing algorithm performs well for stack-allocated arrays, but poorly for arrays on the heap. Example below uses i%M (i modulus M) to count every M-th integer in respective array element. For simplicity, imagine N=1000000, M=10. If N%M==0, then the result should be that every element of bins[] is equal to N/M: #pragma omp for for (int

does openmp allocate memory and free all after

半腔热情 提交于 2019-12-17 20:27:23
问题 Does openmp allocate memory and free all memory? Because I ran valgrind, and did free all my lists.. Everything that I malloc, did I free. ==11442== HEAP SUMMARY: ==11442== in use at exit: 192 bytes in 1 blocks ==11442== total heap usage: 2,001 allocs, 2,000 frees, 2,917,280 bytes allocated ==11442== ==11442== LEAK SUMMARY: ==11442== definitely lost: 0 bytes in 0 blocks ==11442== indirectly lost: 0 bytes in 0 blocks ==11442== possibly lost: 0 bytes in 0 blocks ==11442== still reachable: 192

OpenMP support in Xcode 6 (clang 3.5)

喜夏-厌秋 提交于 2019-12-17 20:25:23
问题 xcode 6 is based on clang 3.5; on osx 10.9.5 running clang++ --version from the command line reports Apple LLVM version 6.0 (clang-600.0.51) (based on LLVM 3.5svn) so I supposed that Apple included openmp support given the fact that in the clang 3.5 release notes http://llvm.org/releases/3.5.0/tools/clang/docs/ReleaseNotes.html the clang developers claim partial openmp support. But it seems that the "-fopenmp" argument is still not recognized. Any hints? 回答1: Clang still does not fully

Parallelizing a Breadth-First Search

∥☆過路亽.° 提交于 2019-12-17 20:24:15
问题 I just taught myself some OpenMP and this could be stupid. Basically I'm trying to parallelize a breadth first search program in c++, with each node taking a long time to process. Here's an example code: queue<node*> q; q.push(head); while (!q.empty()) { qSize = q.size(); for (int i = 0; i < qSize; i++) { node* currNode = q.front(); q.pop(); doStuff(currNode); q.push(currNode); } } The processing function doStuff() is quite expensive and I want to parallelize it. However if I parallelize the

Conditional “pragma omp”

微笑、不失礼 提交于 2019-12-17 19:52:15
问题 I am trying different kinds of parallelization using OpenMP. As a result I have several lines of #pragma omp parallel for in my code which I (un-)comment alternating. Is there a way to make these lines conditional with something like the following, not working code? define OMPflag 1 #if OMPFlag pragma omp parallel for for ... 回答1: An OpenMP parallel construct can have an if clause specified. In Fortran I'd write something like this: !$omp parallel if(n>25) ... I sometimes use this when a

Reduction with OpenMP

只谈情不闲聊 提交于 2019-12-17 19:34:10
问题 I am trying to compute mean of a 2d matrix using openmp. This 2d matrix is actually an image. I am doing the thread-wise division of data. For example, if I have N threads than I process Rows/ N number of rows with thread0 , and so on. My question is: Can I use the openmp reduction clause with " #pragma omp parallel "? #pragma omp parallel reduction( + : sum ) { if( thread == 0 ) bla bla code sum = sum + val; else if( thread == 1 ) bla bla code sum = sum + val; } 回答1: Yes, you can - the

How to define a object or struct as threadprivate in OpenMP?

泪湿孤枕 提交于 2019-12-17 18:59:01
问题 I don't know how to make a struct or object as threadprivate, what I'm doing generates a error: struct point2d{ int x; int y; point2d(){ x = 0; y = 0; } //copy constructor point2d(point2d& p){ x = p.x; y = p.y; } }; I declare a static structure and try to make them threadprivate static point2d myPoint; #pragma omp threadprivate(myPoint) It generates an error: error C3057: 'myPoint' : dynamic initialization of 'threadprivate' symbols is not currently supported Does it means that current openmp