PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

CUDA-x86.

Call pgfortran routines with OpenMP from g++

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



Joined: 06 Apr 2012
Posts: 1

PostPosted: Fri Apr 06, 2012 1:10 am    Post subject: Call pgfortran routines with OpenMP from g++ Reply with quote

Hello,

I'd like to call some fortran code with OpenMP parallel regions from c++ code, which will need to be compiled with g++ rather than the pgc++ compiler. I was trying to follow http://www.pgroup.com/support/interlan.htm#pgf77-f90-g%2B%2B. Things are fine without using omp, but I get segfaults if the omp part is present. Can someone please take a look? Here is the code:

t1m.for
Code:

      subroutine t1m_fort(n, a, b, c)
        integer i,n
        real a(*),b(*),c(*)
!$OMP PARALLEL DO DEFAULT(SHARED)
        do i=1,n
          c(i) = a(i)+b(i)
        end do
!$OMP END PARALLEL DO
      end


t1m.cpp
Code:

extern "C" void t1m_fort_(int *, float *, float *, float *);
extern "C" void pghpf_init(int *);
int __argc_save;
char **__argv_save;
static int zz = 0;

int main(int argc, char **argv)
{
    __argc_save = argc;
    __argv_save = argv;
    pghpf_init(&zz);

    int n = 100;
    float *a = new float[n];
    float *b = new float[n];
    float *c = new float[n];
    for (int i = 0; i < n; i++) {
        a[i] = i;
        b[i] = 2 * i;
        c[i] = 0;
    }

    t1m_fort_(&n, a, b, c);

    delete [] a;
    delete [] b;
    delete [] c;
    return 0;
}


Compilation:
Code:

pgf90 -c -mp -Minfo=all t1m.for -o t1m_for.o
g++ t1m.cpp t1m_for.o -L/opt/pgi/linux86-64/12.3/libso -lpgmp -lnuma -lpgf90 -lpgf90_rpm1 -lpgf902 -lpgf90rtl -lpgftnrtl -lm -lpgc -lgcc -lrt -o t1m


Thanks,
Andy
Back to top
View user's profile
mkcolg



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

PostPosted: Fri Apr 06, 2012 8:11 am    Post subject: Reply with quote

Hi Andy,

Our OpenMP run time library needs an initialisation routine linked in. You have two options. Either add the "initmp.o" object to your link, or link with pgf90. Personally, I recommend linking with the Fortran compiler since it's typically easier to add "-Mnomain" then to try and figure our what libraries and objects are needed.

Hope this helps,
Mat

For example:
Code:
% pgf90 -c -mp t1m_for.f90 -o t1m_for.o
% g++ t1m.cpp t1m_for.o -L/opt/pgi/linux86-64/12.3/libso -lpgmp -lnuma -lpgf90 -lpgf90_rpm1 -lpgf902 -lpgf90rtl -lpgftnrtl -lm -lpgc -lgcc -lrt -o t1m /opt/pgi/linux86-64/12.3/lib/initmp.o
% t1m
C=3 297


Code:
% g++ -c t1m.cpp
% pgf90 -Mnomain -mp t1m.o t1m_for.f90 -lstdc++
t1m_for.f90:
i% a.out
C=3 297
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