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

Memory allocation problems using mixed c++ and fortran language

guru_matze
Beginner
300 Views
Hello,

i am working on a c++ projekt which stand-alone works fine. I have mixed it with an existing fortran projekt (which itself stand-alone works fine). I made a lib from the Fortran project and linked it from the c++-code. This also works fine, as long as my c++ code is not using more then 70MB. When the memory use rises above this boundary from my c++ code, i get bad_alloc or memory acces violation errors. If the cpp code stays below the 70MB and the fortran code mades an attempt to get more memory then the 70MB boundary it has not enough memory. I have 2GB Ram so this can not be the Problem.
If the Program stays under this 70MB everything works fine. When i comment out the class which communicates with fortran the c++ code has no problems running with a higher memory usage, but when the class exists (even without using it!) the c++ code gets memory Problems.

Error: Microsoft C++ exception: std::bad_alloc @ 0x0012f8d4.

Every project i am using is linked with the multithreaded-dll runtime-library and every fortran project is using the calling convention: C, Reference
It is running on WinXP Pro with Visual studio 2003 and intel Fortran compiler 9.0.
Does anybody has experienced similar problems?
Thanks a lot for every answer.

Best regards,
Matthias

p.s.: perhaps this helps:
kernel32.dll!7c812a5b()
kernel32.dll!7c812a5b()
ntdll.dll!7c9206eb()
> msvcr71.dll!_heap_alloc(unsigned int size=1243348) Zeile 212 C
msvcp71.dll!std::_Nomemory() Zeile 9 + 0x1e C++
InGridFeat3D.exe!operator new(unsigned int size=1701052416) Zeile 12 C++
msvcr71.dll!_heap_alloc(unsigned int size=2084152256) Zeile 212 C
msvcr71.dll!__crtExitProcess(int status=2083923945) Zeile 463 + 0x9 C
ffffffff()
msvcr71.dll!_heap_alloc(unsigned int size=1767910504) Zeile 212 + 0x5 C


0 Kudos
4 Replies
TimP
Honored Contributor III
300 Views

The problem of shrinking available virtual address space on 32-bit XP-SP2 is well known. Too many factors enter in to cover them all here, including permanent allocations to other applications which may be running on your system. You didn't say whether you set the boot-time /3GB switch, which makes more space available for Fortran ALLOCATABLE arrays.

A few customers have to stay with Windows 2000 until they are prepared to move to 64-bit.

0 Kudos
guru_matze
Beginner
300 Views

Hello again,

thanks for your quick answer. I had no idea that such a switch exists in windows. I tried it and with the /3GB switch i am now able to allocate about 150MB, which is twice as much as before,without an error. That helps a little bit but my software must be able to deal with much more. The Problem exists on my Desktop PC as well as on my Laptop, so i think there are no other applikations playing a role.

Do you think the problems wont exist on a 64-bit windows? It is worth a try, but is there anyother chance to fix this problem?I dont know if my Visual Studio is 64-bit compatible.

Thanks again.

0 Kudos
TimP
Honored Contributor III
300 Views

Normally, I would have thought Win64 could solve such a problem. But, I would have thought /3GB would give more than 150MB, so I don't know.

In order to run Visual Studio on 64-bit, you need VS2005. The 64-bit libraries are downloadable, in case you already have VS2005.

0 Kudos
Steven_L_Intel1
Employee
300 Views

Something is very wrong. You should be able to allocate well over 1GB in normal circumstances. I have seen cases where customers mistook a number as bytes when it was actually array elements (at 8 or 16 bytes apiece).

I'd like to see this application (source and instructions for running it so I can try to reproduce the problem.) Please attach a ZIP of the projects to an issue you open at Intel Premier Support and say that Steve Lionel asked that it be assigned to him.

I will note that 9.0 is not a supported version, not that that should matter for this issue. 9.0 does not support VS2005, which Tim mentioned as what you need to use VS on x64.

0 Kudos
Reply