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

Question about Steves C# Sample / Datatypes in C# and Fortran

onkelhotte
New Contributor II
1,380 Views

Hi Steve,
Im about to begin a mixed language project, where in C# is I/O andan IVF dll is the mathematical kernel.

In my projects was an older example you posted here some time ago, I couldnt findthat thread any more, it is called csharpsample. There is an c# console application and a fortran dll, where c# calls a fortran subroutine and it passes the results.

I have one general question: Why do you use in c# System.Single and not floatfor fortran real?

Is this equivalence "chart" correct or do I miss something?

fortranc#
real(kind=4) System.Single (why not float?)
real(kind=8) double
real(kind=16) decimal
integer(kind=2) short
integer(kind=4) int
integer(kind=8) long
character*(*) System.Text.StringBuilder
logical bool (or somekind of int?)

Thanks in advance,
Markus

0 Kudos
7 Replies
Steven_L_Intel1
Employee
1,380 Views
I didn't create that sample - I borrowed it from something another user wrote. I don't know C# enough to comment on the different data types it has.

Fortran LOGICAL has no equivalent in C/C++/C#. It is emphatically NOT bool.
0 Kudos
rasa
Beginner
1,380 Views
Is it possible to repost the C# DLL sample or provide a link to it? Looks like there is some momentum buiding up to use this approach in the near future for many users.

If someone can give an example on handling different data types, arrays or module data that would be great. I am sure we can all benefit from a sample program.

Thanks.
0 Kudos
Steven_L_Intel1
Employee
1,380 Views
Here's the sample I have - I haven't looked at this in a while.
0 Kudos
onkelhotte
New Contributor II
1,380 Views

Yes, this is the example I have on my disk.

Logical is not bool, I know that. So you have to create a workaround, passing an int = 0 as .false. and != 0 as .true. or something like that.

Iknow why the author uses System.Single instead of float. Its the same :-) float isthe C# keyword for the .NET Class System.Single, so it doesnt matter.

The good thing in this example is, that the array size is unknown to the Fortran DLL (nArry(*)). The bad thing is, it only works with 1 dimensional arrays. Does anybody knows how to change this into 2 or 3 dimensional arrays?

I try to avoid allocatable arrays, but sometimes you dont have the choice :-)


When you work with more dimensional arrays you have to consider that C# and Fortran arrays have a different way how the data isstored in memory. A C# Array[x,y,z] is the Fortran Array(z,y,x).

Markus

0 Kudos
onkelhotte
New Contributor II
1,380 Views
I have a problem with this sample under Windows764-Bit.

When I call the subroutine, the Exception System.BadImageFormatException appears.

I know that this has something to do with x86 and x64 settings in Visual Studio. I changed the C# project to x86, the IVF project is Win32. But it still wont work.

This happens with newly created C#.GUI and IVF.dll too

Does anybody has similar problems andmaybe a solution?

Markus
0 Kudos
Steven_L_Intel1
Employee
1,380 Views
I recall a similar problem when I was working on the VB.NET sample. You're on the right track, but I think you may have to do both as x64 on an x64 system. I will play with this and see what I get.
0 Kudos
onkelhotte
New Contributor II
1,380 Views
At some point it worked. It had something to do with the x86 settings, but I dont know how I fixed it (shame on me).

Now Im stuck to let this C# program communicate through this DLL with a Fortran program as shared memory (http://software.intel.com/en-us/forums/showpost.php?p=169028).

Ive found some posts and I think there are 2 problems: First, Windows7 (and Vista too) uses Shared Memory differently than WindowsXP. Furthermore, .NET programs run in seperate "application domains".

Im on it :-)

Markus
0 Kudos
Reply