Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
1 View

need help calling C from fortran

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
Highlighted
Valued Contributor III
1 View

Review this thread and other

0 Kudos
Highlighted
Beginner
1 View

Thanks for the reply,

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
Highlighted
1 View

I had code with a large stack

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
Highlighted
Beginner
1 View

Hmmm.  The code I'm working

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
Highlighted
Black Belt
1 View

Stack Reserve Size sets the

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.

Steve (aka "Doctor Fortran") - https://stevelionel.com/drfortran
0 Kudos
Highlighted
Beginner
1 View

Thanks, Steve.  Visual Studio

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
Highlighted
Black Belt
1 View

Leave the other values alone.

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!)

Steve (aka "Doctor Fortran") - https://stevelionel.com/drfortran
0 Kudos