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

Win IVF 9.1: WinAPI for GetProcessMemoryInfo

john3
Beginner
1,448 Views
Recently found how to get WinXP IVF 9.1 task manager memory information using the api GetProcessMemoryInfo. Used the Microsoft C code example and linked to my f90 code as a library. The desired piece of information is the peak process memory usage.

Question: Is there an IVF 9.1 module which would allow one to write this api call in Fortran directly? The C header was #include "psapi.h".

Need a f90 interface for GetProcessMemoryInfo and for the data type PROCESS_MEMORY_COUNTERS.

Any such thing? Thanks
0 Kudos
12 Replies
Steven_L_Intel1
Employee
1,448 Views
I'm putting together a PSAPI module. Stay tuned.
0 Kudos
john3
Beginner
1,448 Views
Sounds very good. Any idea when?

How does one know what WinXP api's are in the various Fortran include modules? The documentation almost seems to say one must just look inside the various *.f90 files once a desired api is identified. Trouble is, there are more *.f90 include files than one can practially look in.

Thanks.
0 Kudos
Steven_L_Intel1
Employee
1,448 Views
Well. I would have been able to post it today, but I had a brain cramp and managed to wipe out hours of work without chance of recovery (overwrote the file). Sigh. I'll start over and should have at least that interface done tomorrow.

All you really need to do is look in the Microsoft documentation for the API you want and look to see which .lib it is in. That's the name of the module to use. kernel32.lib = USE KERNEL32, etc.
0 Kudos
anthonyrichards
New Contributor III
1,448 Views
Re; searching for interface blocks for windows API functions: I use CVF in MS DevStudio and under the EDIT menu is a 'Find in files' option which lets you browse to a folder and enter a string to be searched for. I have used this many times to locate an interface block or TYPE definition in the various modules in the INCLUDE folder. It's no problem.
0 Kudos
Steven_L_Intel1
Employee
1,448 Views
Ok, attached is a ZIP with a partial PSAPI module, including definitions needed for using GetProcessMemoryInfo, and a Fortran port of the MSDN example for this API. Let me know what you think.

I'll work on filling in the module when I get time (and will try to get it added to the product in the future.)
(Virus scan in progress ...)
0 Kudos
Steven_L_Intel1
Employee
1,448 Views
Here's a complete PSAPI module and a test program that demonstrates a couple of the interfaces, including the one you wanted. Let me know what you think.
(Virus scan in progress ...)
0 Kudos
anthonyrichards
New Contributor III
1,448 Views

As Boris Becker may have said, losing to Stefan Edberg at Wimbledon:

"Great service, Steve".

0 Kudos
john3
Beginner
1,448 Views
Steve, What a pleasant surprise when I got back from my civic club lunch. Promply installed, set up for my configuration, and best of all, was able to get rid of the C code implemention!

This morning I see you now have the whole package to try.

From what I saw, it looks like the protcol is to have a module to define data structures and a second to define the interfaces with the $DEC's to link directly to the C libraries. Is that about it?

Also liked learning about using !DEC$ OBJCOMMENT lib:"xxx.lib" . Now I don't have to always be specifing libraries on the resource tab in Visual Studio.

Again, Thanks.
0 Kudos
Steven_L_Intel1
Employee
1,448 Views
In the product, all of the datatype and constant definitions are in module IFWINTY, which is then USEd in the API modules and within the interfaces (In F95, this is how you have to do it.) Look at the existing API modules such as kernel32.f90 to see more examples. Since the PSAPI types aren't yet in IFWINTY, I created a new module for them.

In Fortran 2003, there's a new IMPORT statement that can be used in interface blocks that says to make any symbols in the host scope visible in the interface. (You can also select which symbols to import.) With that, one can do away with the separate module and put all the definitions in the one (PSAPI), so instead of USE IFWINTY (or USE PSAPI_TYPES) in each interface, you just have USE IFWINTY in module PSAPI and then an IMPORT in each interface and either put the types and constants in PSAPI or move them to IFWINTY. I'm not sure which we'd choose in the future. IMPORT will be coming next month to an Intel compiler near you (not this week's release.)
0 Kudos
Angus_Yeh
Beginner
1,448 Views

Hi,
Sorry I am aware this is a very old thread. I am trying to find out how to use the API structure "PROCESS_MEMORY_COUNTERS_EX" (the extended version of PROCESS_MEMORY_COUNTERS, as documented here:
But when I searched through psapi.f90, I can only find the type definition, no function that actually accepted the _EX version. I am not very familiar with calling Win API, and what I am essentially trying to do is to find out the Private Bytes of the executing process.
Thanks in advance!
Regards,
Angus
0 Kudos
Steven_L_Intel1
Employee
1,448 Views
Thanks for pointing out this omission. I have attached a revised version of psapi.f90 that takes care of it - just add this to your project. The key is to define a generic interface for GetProcessMemoryInfo with two specific procedures, one that takes the EX structure and one that takes the non-EX structure.

I will have this added to a future release of the compiler.
(Virus scan in progress ...)
0 Kudos
Angus_Yeh
Beginner
1,448 Views
Awesome!
Thank you very much for the ultra fast response. It works. :-)
Regards,
Angus
0 Kudos
Reply