Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

need help calling C from fortran

Brian_Murphy
New Contributor II
373 Views

I have a fortran console application, and I'm having trouble calling a C function.  I am using visual studio 2010.  I made a simple fortran console program that does nothing more than call my C function, and that works fine.  But the console application that I really want to get working will not work.  I have exhaustively compared visual studio project settings, and I can't figure out why one runs and one doesn't.

Are there any likely culprits that would keep one from working?

 

0 Kudos
7 Replies
FortranFan
Honored Contributor II
373 Views
0 Kudos
Brian_Murphy
New Contributor II
373 Views

Thanks for the reply, FortranFan. 

I believe I found the problem.  It was Configuration Properties/Linker/System/Stack Reserve Size was set too big.  Making it smaller got the program working like it should.  The size was set to 500,000,000 which I guess means 500 million bytes.  I don't know why it was set to this.  I don't even know what this setting is for.  I reduced it to 50,000,000 and the C function part works like it should.  Yippee!

The program is a finite element analysis code.  It uses ALLOCATE statements to create the matrices needed for the current model.

 

0 Kudos
NotThatItMatters
Beginner
373 Views

I had code with a large stack reserve size.  It turned out this was due to some use of Fortran functions MERGE and the like without explicit arrays.  For example, a call to MERGE of this type

RESULT = MERGE(TSource, FSource, RESULT > 0.0)

will result in the amount of stack space required to hold RESULT to be forced on the routine.  I continue using the MERGE function, only with each argument allocated and explicitly declared.

0 Kudos
Brian_Murphy
New Contributor II
373 Views

Hmmm.  The code I'm working with doesn't seem to use MERGE anywhere.  When I get done with what I'm currently doing, I may try further reducing the stack reserve size to see what that does.

0 Kudos
Steve_Lionel
Honored Contributor III
373 Views

Stack Reserve Size sets the size of the stack. The maximum stack Windows supports is 1GB, even on 64-bit, but whatever you set for stack takes away from space available for static code and data. (And, on 32-bit, from all available memory.)  If your programI generally recommend setting the Optimization > Heap Arrays option to 0 - this uses the heap for temporaries rather than the stack.

0 Kudos
Brian_Murphy
New Contributor II
373 Views

Thanks, Steve.  Visual Studio 2010 is presenting me 4 options to set; /HEAP:reserve,  /HEAP:reserve,commit,  /STACK:reserve and /STACK:reserve,commit  

/STACK:reserve is the one set to a large value.  The other three are zero.  I anticipate that when I try all four as zero, the code will still run fine.

0 Kudos
Steve_Lionel
Honored Contributor III
373 Views

Leave the other values alone. If one is adjusting Stack Reserve, do it gradually. OpenMP applications typically need a larger than default stack (default is 1MB!)

0 Kudos
Reply