PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

Free OpenACC Webinar

combine pgfortran and g++

 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling
View previous topic :: View next topic  
Author Message
FlashKick



Joined: 25 Jun 2013
Posts: 1

PostPosted: Wed Jul 03, 2013 9:17 am    Post subject: combine pgfortran and g++ Reply with quote

Now I'm working with a scientific project in which we use fortran-cuda from PGI. We have found that PGI's omp support is so poor that we can not have paralleled omp task in some situation by pgfortran. So we decided to pull out something out and make it C++ and compile it with g++.

The other reason why we want to mix PGI's pgfortran compiler with GNU's g++ is that we need to use the pgfortran to compile the cuda-fortran part of our code and we also need to use NVCC from Nvidia( which use g++ to compile the host code) to compile that OMP segments which have CUDA in them and which can not be compiled correctly by pgfortran.

So here is the Fortran code:
Code:
 program taskf
  use omp_lib
  !use iso_c_binding
  integer :: a
  external task
  !a=10
 
!$OMP parallel num_threads(10)
  print*, 'There are ',omp_get_num_threads(),'threads in fortran',' and this is thread',    omp_get_thread_num()
!$OMP single
  print *, 'Wining thread is' ,omp_get_thread_num()
  call task(a)
!$OMP end single
!$OMP end parallel
 
 end program taskf


And here is the C++ code

Code:
#include <stdio.h>
#include<stdlib.h>
#include<omp.h>

external "C" void task_(int *a){
     for(int i=0;i<10;++i)
      {
#pragma omp task
          {
printf("from thread %d, num of%d \n",omp_get_thread_num(),omp_get_num_threads());
          }
      }
}


And here is my Makefile:
Code:
 
 task:    taskc.o taskf.o
         gfortran taskf.o taskc.o -o myTask   -lstdc++  -fopenmp
 taskf.o: taskf.f90
         gfortran -c taskf.f90  -fopenmp
 taskc.o: taskc.cpp
         g++ -c taskc.cpp -fopenmp
 clean:  taskf.o taskc.o
         rm  taskf.o taskc.o



At last when I link the C++ object files compiled by g++ and the Fortran object files compiled by pgfortran together, if I don't put a -lgomp option there, there will be link errors. But if I put it there, the behavior of OMP threads is weird. The Fortran can only recognize 1 threads while the C++ can recognize the total 10 threads.

I think the problem is that the two different compiler use different OMP library and gomp is GNU's library. So anyone knows how to link them correctly? Or can someone tell me how to link the PGI's OMP library?
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6210
Location: The Portland Group Inc.

PostPosted: Tue Jul 09, 2013 2:18 pm    Post subject: Reply with quote

Hi Flashkick,

Unfortunately, OpenMP implementations from different vendors are typically not compatible so you will not be able to mix the two different OpenMP.

Note that your best bet is to continue with PGI. It looks like you first reported your issue with our OpenMP implementation back in June. (Logged as TPR#19410) Our engineers determined that our implementation of this particular OpenMP tasking behavior was legal and valid, but is different then what was implemented by GNU and Intel. Hence in order to be consistent with the other vendors, we will update our behavior to match theirs. It was too late to get the update into the 13.7 release, but will be available in September's 13.9 release. (there wont be an August 13.8 release).

Hope this helps,
Mat
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
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 © phpBB Group