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

Accessing Module Data from C#

Bowman__Eric
Novice
362 Views

I am working in a mixed C#, Fortran environment. According to the Intel documentation linked below you can export Data from a module in a DLL. 

https://software.intel.com/en-us/node/535307

I can import functions into my C# app using P/invoke but I cannot for the life of me see how to access that exported memory location from my C# app. Any tips on how to do this? 

Eric

0 Kudos
7 Replies
JohnNichols
Valued Contributor III
362 Views

I had this working a few years ago, but there have been changes in C# and Fortran since then so it might take some work 

I do a lot of work in C# and a lot in Fortran 

They do not mix well. 

It is easier to rewrite in one of the languages 

John

0 Kudos
FortranFan
Honored Contributor II
362 Views

See quote #3 in your other thread: https://software.intel.com/en-us/forums/intel-fortran-compiler/topic/831630#comment-1947380

0 Kudos
JohnNichols
Valued Contributor III
362 Views

Dear Fortran Fan:

I agree with your comments - mixing C# and Fortran is a really bad idea. 

Unless your code is longer than 5000 lines it is always easier to rewrite C# as Fortran and pickup the speed advantage and the ability to bring your code to this forum. 

My only problem is that some of our critical  equipment has C# drivers and so it is not easy to fix this issue an this is the best equipment. 

C# is also useful for database connection, which is not so easy with Fortran, you can use the German code but it is not pleasant.

Horses for courses, 

Jhn

0 Kudos
Steve_Lionel
Honored Contributor III
362 Views

I don't agree that mixing Fortran with other languages is a "bad idea". On the contrary, Fortran's interoperability features are a strength and Fortran users have been mixing in other languages for decades. You just have to get the interfaces right. 

0 Kudos
FortranFan
Honored Contributor II
362 Views

Nichols, John wrote:

Dear Fortran Fan:

I agree with your comments - mixing C# and Fortran is a really bad idea. ..

John,

My comment in that other thread only pertained to OP wanting a reference in C# side to an entity (a de facto "global" variable) in a module in Fortran, that such a pursuit can lead to "abuse" and be unsafe.

Re: mixing C# and unmanaged code (per Microsoft terminology on Windows OS where Fortran is but one such usually, at least with Intel Fortran) has many valid use cases, it's supported by Microsoft in more ways than one, so readers here need not shun it rather they should focus on what can help them in their code and formulate and explain their needs - many can then suggest options how to achieve their goals.

 

0 Kudos
JohnNichols
Valued Contributor III
362 Views

Dear Steve and Fortran Fan:

I love programming in LISP, as far as I am concerned it is the perfect theoretical language, but it suffers from speed issues and it is not really supported by major houses. 

I like programming in Fortran because of the speed. 

At the moment we are pushing out NUC Core i3 to do heavy lifting work on remote sites, we want it to run multiple threads and to have no conflicts, this is a problem as we have very limited time to do each stage and complete -- I wish I could do this in Fortran - but it is not possible - I assure you I tried for several months. 

I endure programming in C# -- the manufacturer gave us a product  that communicates 2000 times per second in C# and there are no alternatives.  So I can program moderately well in C#. But it does well in the field. 

I learnt Python to program in Rhino, it was the least pleasant time of my recent life for work. Python is the exact opposite to LISP and everywhere you go you meet Python. 

I program in PHP and MYSQL to run a web site. Interestingly I can generate the graphs with 300000 data points in less than 30 seconds using a neat little program started by E. Bruggeman, but I extended it a lot. To download the same data takes 40 minutes over the web. 

Yes one can do Fortran and other languages, but as mecej4 once pointed out with my water supply analysis program it would run much faster in Fortran. Fortran and C# are so close it is easier to translate the C# into Fortran for numerical methods.  If you need MySQL access and other things then you are forced to use other languages., so C# has its uses with NET 7 etc. 

As in all things it is personal preference and unlike the average modern company or university that gives you a completely locked down computer, I cannot even put winareotweaker on my work machine, one does have a choice. 

So:

when I Python I dream of being strapped to an iceberg and waiting for the Titanic to hit.  I am praying for the Titanic. 

When I use PHP and MySQL I sort of enjoy the experience because it gives me great product. 

When I C# I am doing it because I am forced to, a bit like a 14 hour LAX to Sydney flight, but with a bar frig. But we get great data. 

When I Fortran I think of this forum and remember punch cards - remember Steve bend the punch cards and ____ the man.  

Lisp is a time with the Gods. 

Let us not speak of C -- whoever invented that language took UNIX and tried to make a fast lisp and failed. 

Great thing about America -- I am entitled to my bent opinion. 

Steve:  I grabbed the following code from ACM Algorithm 670 - it runs on a VAX apparently but gives one interesting error  in Intel -- why did it run on the VAX? As I never used one I cannot say.

John

0 Kudos
JohnNichols
Valued Contributor III
362 Views

Steve:

Apologies, I got it working -- there were several program in the files - no main unit - really weird. 

John

0 Kudos
Reply