openmp

Why is this OpenMP program giving me different answers every time?

余生长醉 提交于 2019-12-13 14:06:06
问题 I'm trying make this program run with multiple threads. #include <stdio.h> #include <time.h> #include <omp.h> #define NUM_THREADS 4 static long num_steps = 1000000000; int main() { int i; double x, pi, sum = 0.0; double step = 1.0/(double)num_steps; clock_t start = clock(), diff; #pragma omp parallel for num_threads(NUM_THREADS) reduction (+:sum) for (i = 0; i < num_steps; i++) { x = (i+0.5)*step; sum += 4.0/(1.0 + x*x); } #pragma omp ordered pi = step*sum; printf("pi = %.15f\n %d iterations

What preprocessor define does -fopenmp provide?

若如初见. 提交于 2019-12-13 12:31:26
问题 I've got some code that can run with (or without) OpenMP - it depends on how the user sets up the makefile. If they want to run with OpenMP, then they just add -fopenmp to CFLAGS and CXXFLAGS . I'm trying to determine what preprocessor macro I can use to tell when -fopenmp is in effect. The omp.h header does not look very interesting: $ cat /usr/lib/gcc/x86_64-linux-gnu/4.8/include/omp.h | grep define #define OMP_H 1 #define _LIBGOMP_OMP_LOCK_DEFINED 1 # define __GOMP_NOTHROW throw () #

OpenMP library specification

折月煮酒 提交于 2019-12-13 12:09:48
问题 i am new to open mp and i tried an sample program from the official site #include <omp.h> #include <stdio.h> int main() { #pragma omp parallel printf("Hello from thread %d, nthreads %d\n", omp_get_thread_num(), omp_get_num_threads()); } and i have set the library in the eclipse as libgomp in project Properties->GCC c++ linker- but the program say /usr/bin/ld: cannot find -llibgomp can i know where i am wrong 回答1: Try linking with gomp instead of libgomp : library names must be passed to the

Issue with OpenMP thread execution and threadprivate variable

女生的网名这么多〃 提交于 2019-12-13 08:46:10
问题 I have used 8 threads for 8 loops. I have used 'print' to see how the parallel code works. The 0 thread creates problems!I have showed in the attached diagram (please check the attached link below) how the parallel works. I have used threadprivate but it turned out that thread 0 can not get any private threadsafe variables. I have tried with modules as well and got same results! Any idea why the code acts this way? I would appreciate any help or suggestion. Thanks! !$OMP PARALLEL DO do nb=m3

Memory error when using OpenMP with Fortran, running FFTW

荒凉一梦 提交于 2019-12-13 08:13:05
问题 I am testing FFTW in a fortran program, because I need to use it. Since I am working with huge matrixes, my first solution is to use OpenMP. When my matrix has dimension 500 x 500 x 500 , the following error happens: Operating system error: Program aborted. Backtrace: Cannot allocate memory Allocation would exceed memory limit I compiled the code using the following: gfortran -o test teste_fftw_openmp.f90 -I/usr/local/include -L/usr/lib/x86_64-linux-gnu -lfftw3_omp -lfftw3 -lm -fopenmp

Why omp version is slower than serial?

南楼画角 提交于 2019-12-13 07:57:52
问题 It's a follow-up question to this one Now I have the code: #include <iostream> #include <cmath> #include <omp.h> #define max(a, b) (a)>(b)?(a):(b) const int m = 2001; const int n = 2000; const int p = 4; double v[m + 2][m + 2]; double x[m + 2]; double y[m + 2]; double _new[m + 2][m + 2]; double maxdiffA[p + 1]; int icol, jrow; int main() { omp_set_num_threads(p); double h = 1.0 / (n + 1); double start = omp_get_wtime(); #pragma omp parallel for private(icol) shared(x, y, v, _new) for (icol =

Configure error installing fftw

妖精的绣舞 提交于 2019-12-13 06:46:51
问题 I just followed the instructions here to update my gcc. Now I am trying to install FFTW. So I downloaded the filed here. After I unzip and navigate to that directory I run this: ./configure --enable-mpi --enable-threads --enable-openmp But I get the following error: checking for OpenMP flag of C compiler... unknown configure: error: don't know how to enable OpenMP I know OpenMP didn't work before I updated GCC, but it does now if I do this: export PATH=/usr/local/gcc-6.1.0/bin:$PATH gcc-6.1.0

OpenMP lock vs. critical

╄→гoц情女王★ 提交于 2019-12-13 06:26:17
问题 I'm playing around with locks and critical sections for making a loop thread safe. Here is the code: #pragma omp parallel for num_threads(4) private(k, f_part_k, len, len_3, mg, fact) for (k = part+1; k < n; k++) { /* Compute force on part due to k */ f_part_k[X] = curr[part].s[X] - curr[k].s[X]; f_part_k[Y] = curr[part].s[Y] - curr[k].s[Y]; len = sqrt(f_part_k[X]*f_part_k[X] + f_part_k[Y]*f_part_k[Y]); len_3 = len*len*len; mg = -G*curr[part].m*curr[k].m; fact = mg/len_3; f_part_k[X] *= fact;

C++ exceptions in OpenMP parallel regions: What to do?

最后都变了- 提交于 2019-12-13 06:09:58
问题 I've been reading about the topic and I would like to know if I got things right. Since an exception thrown in a thread must be handled in the thread, I found by searching the web that what people do most often is to create some means to report the exceptions threads have dealt with after they all finish their tasks. Now, as an example, suppose I have a reduction operation, like a sum, and a thread returns NaN, it means that the other threads just wasted time. Since prematurely ending a

Global Variables in Fortran OpenMP

不问归期 提交于 2019-12-13 04:54:07
问题 Why the following code in Fortran only works if I put the loop variables 'i' and 'j' as input arguments of the subroutine 'mat_init'? The loop variables 'i' and 'j' are declared as private, so shouldn't they remain private inside the subroutine when I call it? program main use omp_lib implicit none real(8), dimension(:,:), allocatable:: A integer:: i, j, n n = 20 allocate(A(n,n)); A(:,:) = 0.0d+00 !$omp parallel do private(i, j) do i=1,n do j=1,n call mat_init end do end do do i=1,n write(*,'