| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| 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 |
|
#2
| |||
| |||
| 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. |
|
#3
| |||
| |||
| cheers for the help. |
|
#4
| |||
| |||
| 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 |
|
#5
| |||
| |||
| 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 |
|
#6
| |||
| |||
| 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 |
|
#7
| |||
| |||
| 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 |
|
#8
| |||
| |||
| 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 |
|
#9
| |||
| |||
| 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 |
|
#10
| |||
| |||
| 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. |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.