compiler flag question

This is a discussion on compiler flag question within the Fortran forums in Programming Languages category; Hi How can I make my code do something depending on my compiler flag? For example, if I use the -openmp flag I want a loop to have a different range. i.e. if (flag -openmp) do i=1,10 else do i=1,5 endif do loop enddo Thanks...

Go Back   Application Development Forum > Programming Languages > Fortran

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-20-2008, 08:37 AM
tomguest@hotmail.com
Guest
 
Default compiler flag question

Hi

How can I make my code do something depending on my compiler flag?
For example, if I use the -openmp flag I want a loop to have a
different range.

i.e.

if (flag -openmp)
do i=1,10
else
do i=1,5
endif

do loop

enddo

Thanks
Reply With Quote
  #2  
Old 08-20-2008, 10:32 AM
Tim Prince
Guest
 
Default Re: compiler flag question

tomguest@hotmail.com wrote:
> Hi
>
> How can I make my code do something depending on my compiler flag?
> For example, if I use the -openmp flag I want a loop to have a
> different range.
>
> i.e.
>
> if (flag -openmp)
> do i=1,10
> else
> do i=1,5
> endif
>
> do loop
>
> enddo


You can find examples on the use of
#ifdef _OPENMP
by a simple web search.
Reply With Quote
  #3  
Old 08-20-2008, 10:52 AM
tomguest@hotmail.com
Guest
 
Default Re: compiler flag question

cheers for the help.
Reply With Quote
  #4  
Old 08-20-2008, 04:42 PM
glen herrmannsfeldt
Guest
 
Default Re: compiler flag question

tomguest@hotmail.com wrote:

> How can I make my code do something depending on my compiler flag?
> For example, if I use the -openmp flag I want a loop to have a
> different range.


> if (flag -openmp)
> do i=1,10
> else
> do i=1,5
> endif


You can't do that in Fortran, or pretty much any
compiled language. (I have seen it done in BASIC).

But you say compiler flag. If you use the C preprocessor,
you can do

#ifdef OPENMP
do i=1,10
#else
do i=1,5
#endif

where OPENMP is a preprocessor symbol, defined either
with #define, or a compiler option such is -DOPENMP

At compile time, one or the other will be compiled.

-- glen

Reply With Quote
  #5  
Old 08-20-2008, 09:23 PM
Ron Ford
Guest
 
Default Re: compiler flag question

On Wed, 20 Aug 2008 12:42:03 -0800, glen herrmannsfeldt posted:

> tomguest@hotmail.com wrote:
>
>> How can I make my code do something depending on my compiler flag?
>> For example, if I use the -openmp flag I want a loop to have a
>> different range.

>
>> if (flag -openmp)
>> do i=1,10
>> else
>> do i=1,5
>> endif

>
> You can't do that in Fortran, or pretty much any
> compiled language. (I have seen it done in BASIC).
>
> But you say compiler flag. If you use the C preprocessor,
> you can do
>
> #ifdef OPENMP
> do i=1,10
> #else
> do i=1,5
> #endif
>
> where OPENMP is a preprocessor symbol, defined either
> with #define, or a compiler option such is -DOPENMP
>
> At compile time, one or the other will be compiled.
>
> -- glen


Yikes. You can do that with C, but would you?
--
Wealth - any income that is at least one hundred dollars more a year than
the income of one's wife's sister's husband. 6
H. L. Mencken
Reply With Quote
  #6  
Old 08-21-2008, 12:15 AM
tju329
Guest
 
Default Re: compiler flag question

On Aug 20, 8:37*pm, tomgu...@hotmail.com wrote:
> Hi
>
> How can I make my code do something depending on my compiler flag?
> For example, if I use the -openmp flag I want a loop to have a
> different range.
>
> i.e.
>
> if (flag -openmp)
> * do i=1,10
> else
> * do i=1,5
> endif
>
> do loop
>
> enddo
>
> Thanks


If machine dependent, use
#ifdef _OPENMP
call sub_openmp ( parms )
#else
call sub_other (parms )
#endif


Reply With Quote
  #7  
Old 08-21-2008, 03:07 AM
Arjen Markus
Guest
 
Default Re: compiler flag question

On 21 aug, 03:23, Ron Ford <r...@example.invalid> wrote:
> On Wed, 20 Aug 2008 12:42:03 -0800, glen herrmannsfeldt posted:
>
>
>
>
>
> > tomgu...@hotmail.com wrote:

>
> >> How can I make my code do something depending on my compiler flag?
> >> For example, if I use the -openmp flag I want a loop to have a
> >> different range.

>
> >> if (flag -openmp)
> >> * do i=1,10
> >> else
> >> * do i=1,5
> >> endif

>
> > You can't do that in Fortran, or pretty much any
> > compiled language. *(I have seen it done in BASIC).

>
> > But you say compiler flag. *If you use the C preprocessor,
> > you can do

>
> > #ifdef OPENMP
> > * * do i=1,10
> > #else
> > * * do i=1,5
> > #endif

>
> > where OPENMP is a preprocessor symbol, defined either
> > with #define, or a compiler option such is -DOPENMP

>
> > At compile time, one or the other will be compiled.

>
> > -- glen

>
> Yikes. *You can do that with C, but would you?
> --
> Wealth - any income that is at least one hundred dollars more a year than
> the income of one's wife's sister's husband. 6
> H. L. Mencken- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -


You can use COCO if you want a Fortran-only solution

Regards,

Arjen
Reply With Quote
  #8  
Old 08-21-2008, 03:08 AM
Arjen Markus
Guest
 
Default Re: compiler flag question

On 20 aug, 14:37, tomgu...@hotmail.com wrote:
> Hi
>
> How can I make my code do something depending on my compiler flag?
> For example, if I use the -openmp flag I want a loop to have a
> different range.
>
> i.e.
>
> if (flag -openmp)
> * do i=1,10
> else
> * do i=1,5
> endif
>
> do loop
>
> enddo
>
> Thanks


Out of curiosity: why is the loop different if you use OpenMP
than if you don't - especially as this is a compile-time
decision, not part of the input for the problem.

Regards,

Arjen
Reply With Quote
  #9  
Old 08-21-2008, 05:03 AM
Reinhold Bader
Guest
 
Default Re: compiler flag question

How about

imax = 5
!$ imax = 10
do i=1, imax
:
end do

Regards

tomguest@hotmail.com schrieb:
> Hi
>
> How can I make my code do something depending on my compiler flag?
> For example, if I use the -openmp flag I want a loop to have a
> different range.
>
> i.e.
>
> if (flag -openmp)
> do i=1,10
> else
> do i=1,5
> endif
>
> do loop
>
> enddo
>
> Thanks

Reply With Quote
  #10  
Old 08-21-2008, 05:59 AM
tomguest@hotmail.com
Guest
 
Default Re: compiler flag question

I basically want to have different output to certain files depending
on how the user compiles the code.

I just gave the loop problem as an example. I'm also incorporating
some other features that I want to enable by compiler flags.
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 02:51 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.