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

multiple DLLs and file access

trnsys
Beginner
237 Views

I work on a piece of software that has an exe/dll structure. There can actually be multiple dlls, all of them in Fortran. The main DLL (TRNDLL) loads the other DLLs if those DLLs contain routines that are needed. In migrating from the CVF to the IVF compiler, we've run into a few new behaviors that have our users a bit up in arms. I think they may all be related (which is why I am cramming them all into one thread)

1. The main DLL opens a list file and assigns it logical unit 6. With CVF and without jumping through any hoops, if a routine in one of the other DLLs had a WRITE(6,...) line in it, the result was written to the list file. This doesn't seem to work anymore. Those WRITE statements in external DLL routines that know ahead of time that the logical unit of the list file was 6 can't seem to write directly to the list file.

2. Some of the external DLLs make a call back to a routine in the main DLL that reads a text data file and then passes the contents to the extenal DLL. If all of the DLLs are compiled in IVF or all of the DLLs are compiled in CVF everything works fine. However, if there is a mixture of DLLs (some compiled in CVF others compiled in IVF), we get garbage returned to the external DLL. All of the file opening and reading takes place in routines in the main DLL. Only numerical values are passed back and forth (although one of them is the logical unit number of the file to be read (an INTEGER)).

3. It used to be that we could launch the exe (which would call the main DLL which inturn reads the input file, generates the list file and starts in on its execution). We could then launch the exe again, giving it the same input file to read (with or without changes) and off it would go. To be honest, I am not sure how this was working under CVF. However, with IVF, I now get a visual fortran run-time error "write to READONLY file" error when I launch the second instance of the exe. Before I go trying to clean up the error so that it is handled more cleanly in our code, I thought I'd inquire about any compiler settings that I might have missed or whether this was just a bug in the CVF compiler that we all happened to find handy...

I apologize for the length of my post...Any thoughts would be most welcome.

Best,

David

0 Kudos
1 Reply
Steven_L_Intel1
Employee
237 Views

First, all of your DLLs and your EXE need to be linked against the same set of DLL run-time libraries. The DLLs default to this but the EXE may not. You want "Multithreaded DLL" under Fortran > Libraries > Use Run-Time Library.

Second, if you mix CVF and IVF code, you cannot share I/O units between the two. Also, the default calling conventions are different so you either need to know which compiler was used or use directives or compiler options to force both compilers to the same conventions.

Third, I don't fully understand what you are doing when you get the I/O error. Can you explain this in more detail? Are you sure that the previous invocation of the EXE has finished running? I remember with CVF we had some cases where Windows kept a file open for a half second or so after an EXE finished which could cause errors if you ran another EXE right away. If you wait a few seconds to start the second EXE, does that help?

0 Kudos
Reply