|
| View previous topic :: View next topic |
| Author |
Message |
AZaldei
Joined: 22 Apr 2013 Posts: 9
|
Posted: Fri Apr 26, 2013 12:57 am Post subject: [SOLVED] Non-working OpenMP |
|
|
Hi all,
I'm currently interested in compiling the WRF-ARW meteorological model in smpar (i.e.: multithreaded method), but I seem to have some issues with OpenMP.
The machine I'm working on has an 8 core intel CPU i7, therefore should be fully capable of multithreading. I'm testing such capability by compiling and running the example program at page 55 of the PGI Compiler User's Guide (Release 2013) on an x64 Ubuntu 12.10 OS (bash shell).
I've created a FORTRAN file (main.f) with the example program and I'm proceeding this way:
| Code: |
modelstation@modelstation:~$ export OMP_NUM_THREADS=8
modelstation@modelstation:~$ pgf90 -mp main.f
|
Now, by running the executable, I'm expecting to see 8 threads, but the output is this:
| Code: |
Thread 0 local sum: 500500.0000000000
Global Sum: 500500.0000000000
FORTRAN STOP
|
I don't know exactly why and I do not know exactly how to proceed (it's my first attempt at multithreaded computing).
If it may be helpful for diagnostics: while looking for solutions I've also tried testing the OpenMP suggested test-program ([url] http://openmp.org/wp/openmp-compilers/ [/url]) and I received a "missing predefs.h" error, which I solved by installing libc6-dev-i386 (following this suggestion [url] http://ubuntuforums.org/showthread.php?t=1877944 [/url]). Even in that case I could see only one thread instead of the expected 8.
Thanks for your help and Best Regards!
Last edited by AZaldei on Tue May 07, 2013 7:17 am; edited 1 time in total |
|
| Back to top |
|
 |
TheMatt
Joined: 06 Jul 2009 Posts: 263 Location: Greenbelt, MD
|
Posted: Mon Apr 29, 2013 9:18 am Post subject: |
|
|
Hmm. Well, I just took that same program and tried it here:
| Code: | $ pgfortran -mp -Minfo main.f90
main:
13, Parallel region activated
17, Parallel loop activated with static block schedule
20, Barrier
23, Begin critical section (__cs_unspc)
24, End critical section (__cs_unspc)
Parallel region terminated
$ setenv OMP_NUM_THREADS 1
$ ./a.out
Thread 0 local sum: 500500.0000000000
Global Sum: 500500.0000000000
FORTRAN STOP
$ setenv OMP_NUM_THREADS 8
$ ./a.out
Thread 2 local sum: 39125.00000000000
Thread 4 local sum: 70375.00000000000
Thread 6 local sum: 101625.0000000000
Thread 0 local sum: 7875.000000000000
Thread 7 local sum: 117250.0000000000
Thread 1 local sum: 23500.00000000000
Thread 5 local sum: 86000.00000000000
Thread 3 local sum: 54750.00000000000
Global Sum: 500500.0000000000
FORTRAN STOP | and similarly for the OpenMP test case.
One thing you can try is to hardwire the number of threads and see if that works (note the num_threads):
| Code: | #include <omp.h>
#include <stdio.h>
int main() {
#pragma omp parallel num_threads(4)
printf("Hello from thread %d, nthreads %d\n", omp_get_thread_num(), omp_get_num_threads());
} |
This should run with 4 threads regardless of your environment. If it works, then something in your environment is setting OMP_NUM_THREADS back to 1 somehow.
Matt |
|
| Back to top |
|
 |
AZaldei
Joined: 22 Apr 2013 Posts: 9
|
Posted: Tue Apr 30, 2013 1:08 am Post subject: |
|
|
Thanks for the input!
Weird thing is that, before seeing your answer, I've also tried a different couple of programs, both fortran
| Code: |
C******************************************************************************
C FILE: omp_hello.f
C DESCRIPTION:
C OpenMP Example - Hello World - Fortran Version
C In this simple example, the master thread forks a parallel region.
C All threads in the team obtain their unique thread number and print it.
C The master thread only prints the total number of threads. Two OpenMP
C library routines are used to obtain the number of threads and each
C thread's number.
C AUTHOR: Blaise Barney 5/99
C LAST REVISED:
C******************************************************************************
PROGRAM HELLO
INTEGER NTHREADS, TID, OMP_GET_NUM_THREADS,
+ OMP_GET_THREAD_NUM
C Fork a team of threads giving them their own copies of variables
!$OMP PARALLEL PRIVATE(NTHREADS, TID)
C Obtain thread number
TID = OMP_GET_THREAD_NUM()
PRINT *, 'Hello World from thread = ', TID
C Only master thread does this
IF (TID .EQ. 0) THEN
NTHREADS = OMP_GET_NUM_THREADS()
PRINT *, 'Number of threads = ', NTHREADS
END IF
C All threads join master thread and disband
!$OMP END PARALLEL
END
|
and C
| Code: |
#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 they work fine! They return multiple threads if OMP_NUM_THREADS is exported...it's only main.f that keeps having a single thread issue...
...can't understand why! |
|
| Back to top |
|
 |
mkcolg
Joined: 30 Jun 2004 Posts: 4996 Location: The Portland Group Inc.
|
Posted: Tue Apr 30, 2013 9:23 am Post subject: |
|
|
Hi AZaldei,
Since the same source works for Matt, and you can run other programs under OpenMP, I'm wondering if there is a cut and paste issue in your main.f? Can you please post the source you're using, as well as the compilation line and the output from your run?
Thanks,
Mat |
|
| Back to top |
|
 |
AZaldei
Joined: 22 Apr 2013 Posts: 9
|
Posted: Tue Apr 30, 2013 10:51 am Post subject: |
|
|
Sure! Here is the program:
| Code: |
PROGRAM MAIN
INTEGER I, N, OMP_GET_THREAD_NUM
REAL*8 V(1000), GSUM, LSUM
GSUM = 0.0D0
N = 1000
DO I = 1, N
V(I) = DBLE(I)
ENDDO
!$OMP PARALLEL PRIVATE(I,LSUM) SHARED(V,GSUM,N)
LSUM = 0.0D0
!$OMP DO
DO I = 1, N
LSUM = LSUM + V(I)
ENDDO
!$OMP END DO
!$OMP CRITICAL
print *, "Thread ",OMP_GET_THREAD_NUM()," local sum: ",LSUM
GSUM = GSUM + LSUM
!$OMP END CRITICAL
!$OMP END PARALLEL
PRINT *, "Global Sum: ",GSUM
STOP
END
|
Here is the compiling options:
| Code: |
modelstation@modelstation:~/Software$ export OMP_NUM_THREADS=8
modelstation@modelstation:~/Software$ pgfortran -mp main.f
|
And here's the output:
| Code: |
modelstation@modelstation:~/Software$ ./a.out
Thread 0 local sum: 500500.0000000000
Global Sum: 500500.0000000000
FORTRAN STOP
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2002 phpBB Group
|