mixed programming (C++ & Fortran) and OpenMP

General OpenMP discussion

mixed programming (C++ & Fortran) and OpenMP

Postby registry » Tue Jan 15, 2008 12:17 pm

I have a function, let say Func1(...), written in C++. It uses a OpenMP extension of C++ launguage and do some parallel job.


This function i call from a fortran program (sarial).
(create .o file with this function and linkage it together with my fortran program )

If i call this Func(...) inside of some C++ program (serial) -> it works fine with any value of threads (export OMP_NUM_THREADS=1..32)
if i call it from my fortran program, it works only with OMP_NUM_THREADS=1 (serial)...
another values bring the program to crash....



The Quastion... should i obey some rules,m if i use OpenMP and mix languages?

Regards,
Registry
registry
 
Posts: 5
Joined: Tue Jan 15, 2008 11:56 am

Re: mixed programming (C++ & Fortran) and OpenMP

Postby registry » Wed Jan 16, 2008 6:38 am

Found.

Fcukin global variables. (Fortran program is a third party program)

Will look for solution.

Thnx.
registry
 
Posts: 5
Joined: Tue Jan 15, 2008 11:56 am

Re: mixed programming (C++ & Fortran) and OpenMP

Postby lfm » Fri Jan 18, 2008 8:09 pm

If you have access to the source code you might be able to use the threadprivate directive to make your f'ing global variables local to each thread.
lfm
 
Posts: 135
Joined: Sun Oct 21, 2007 4:58 pm
Location: OpenMP ARB

Re: mixed programming (C++ & Fortran) and OpenMP

Postby registry » Sat Jan 19, 2008 3:52 am

Yes, i have.

I try to do it. (I mean, to write after every common block !$omp threadprivate .. is not really difficult. )

The situation is bad.

My #pragma omp parallel block is inside of C++ function (Func(...)).
This function Func(...) gets a pointer on a FORTRAN Function (third party, written in Fortran) and calls it inside of its parallel block.
This FORTRAN-Function, let us to call it boo() uses several COMMON Blocks... also, to writing propose.

So, i cannot write inside of boo(..) !$omp parallel copyin (common block id), it would be orphan parallelizing.. i don't want to have it.

But in C++ function (Func(..) )
i cannot use #pragma omp parallel copyin( ...) , coz i don't have (don't want to have) a really difficult interface to transfer of all symbol names of global variables of the object file contains a object code with the boo(...) function, pointer on wich the function Func(...) gets. (I hope, u understand it. )

To better understanding
Func( .. ) is an optimisation algorithm and has to be able just to call any function (with a fixed form of parameters, of course) by pointer on this function.

In serial case -> pointed function may use any global variables, if it needs... also for writing.
By parallel calling -> race conditions... or Sigmention fault.
And that makes me Arghhhh! (Global variables for writing... nightmare for software developers..,. in 21th century)


What would help, if the realisation of OpenMP of given compiler (in my case - xlf95 from IBM) makes sure, that allready threadprivate directive does a copy of content of the variables from master thread. Then i don't need a copyin clause on 'parallel' directive.

So... Good luck me... without any hope on success...
registry
 
Posts: 5
Joined: Tue Jan 15, 2008 11:56 am

Re: mixed programming (C++ & Fortran) and OpenMP

Postby lfm » Sat Jan 19, 2008 10:43 am

How about this: write a dummy fortran subroutine with a parallel copyin of all the common blocks you need:

subroutine dummy
!$omp parallel copyin(/com1/,/com2/, ...)
!$omp end parallel
end subroutine dummy

Then call dummy from your C++ code before you start the first real parallel region.

If you keep the number of threads identical and don't use dynamic scheduling then the threadprivate data will persist across parallel regions. This is required by the specification.
lfm
 
Posts: 135
Joined: Sun Oct 21, 2007 4:58 pm
Location: OpenMP ARB

Re: mixed programming (C++ & Fortran) and OpenMP

Postby registry » Sun Jan 20, 2008 3:50 am

That is an idea... i will try it and post here the result.

Thnx.
registry
 
Posts: 5
Joined: Tue Jan 15, 2008 11:56 am

Re: mixed programming (C++ & Fortran) and OpenMP

Postby registry » Sun Jan 27, 2008 8:01 am

No...

It works fine only with OMP_THREADS_NUM=1 ... also, serial case.

As long i set parallel - > breaks up.

Maybe there is the misstake not on this place and not connected with global vairables... but i have no time more to find it out. This project is really huge and to check race conditions on more than 100 global arrays... have no mood and time.

Thnx for help
registry
 
Posts: 5
Joined: Tue Jan 15, 2008 11:56 am

Re: mixed programming (C++ & Fortran) and OpenMP

Postby lfm » Tue Jan 29, 2008 3:41 pm

OK. You could try using a checking tool (Intel Thread Checker, and Sun has something as well) but it would still be a lot of work. Good luck.
lfm
 
Posts: 135
Joined: Sun Oct 21, 2007 4:58 pm
Location: OpenMP ARB


Return to Using OpenMP

Who is online

Users browsing this forum: Google [Bot] and 3 guests