By the way have anyone tried the approach of using normal x86 FTN95 compiler while wrapping multithreading part into DLL using NET? That approach should have some advantages over complete NET approach like option for /3GB, it is more stable and well checked by orders of magnitude more users. Here could be other pitfalls but right now that looks like another simple way dealing with the threads within this compiler. FTN95 should accept NET DLL like it is doing with DLLs created by many other third party compilers. I have tried this approach but because my NET experience is near zero level i still have not succeeded.
Here what i have done, all 100% are in front of you. I created file the text of which is below called parallel_NET_DLL.f95 which 100% works under NET and compiled it this way for NET
C:> ftn95 parallel_NET_DLL.f95 /clr /multi_threaded
It contains function Parallel_NET_DLL which starts threads. The analog of OBJ file for NET compiler produces is called parallel_NET_DLL.dbk
!
integer function Parallel_NET_DLL ()
include <clearwin.ins>
EXTERNAL runN
parameter (nThrMax=80)
common /threads_/nEmployedThreads, kThreadEnded(nThrMax)
1 print*,' Enter number of parallel threads < 8'
read(*,*) nEmployedThreads
! if(nEmployedThreads.lt.1.or.nEmployedThreads.gt.8) nEmployedThreads=4
call clock@ (time_start)
!...set a flag of thread finished
kThreadEnded(:)=1
do i = 1, nEmployedThreads
CALL CREATE_THREAD@(runN,20+i)
call sleep1@(0.02)
enddo
!...wait till all threads finish
do while (minval(kThreadEnded)==0)
call sleep1@(0.1)
enddo
call clock@ (time_finish)
time = time_finish-time_start
time2= time * nEmployedThreads
print*, 'Elapsed time, total CPU time=', time, time2
goto 1
Parallel_NET_DLL = 1
END function
! =====================================================================
subroutine runN (iThrHandle)
include <clearwin.ins>
parameter (nThrMax=80)
common /threads_/nEmployedThreads, kThreadEnded(nThrMax)
ithr = iThrHandle-20
lock; print*,'Started thread # ', ithr ; end lock
d =2.22
kThreadEnded(ithr) = 0
do i=1,200000000/nEmployedThreads
d=alog(exp(d))
enddo
lock; print*, 'Ended thread # ', ithr ; end lock
kThreadEnded(ithr)=1
end
Then i made DLL out of it this way
C:>dbk_link2 /multi_threaded parallel_NET_DLL.dll parallel_NET_DLL.dbk
Then i created main program file for regular x86 mode which just calls this function Parallel_NET_DLL and compiled it usual way
C:> ftn95 parallelDLLmain.f95
integer Parallel_NET_DLL
external Parallel_NET_DLL
jj = Parallel_NET_DLL()
print*, 'done'
end
At the end i linked OBJ and DLL using regular SLINK
C:> SLINK parallelDLLmain.obj parallel_NET_DLL.dll
Here is BAT file if you named files as i did above
ftn95 parallel_NET_DLL.f95 /clr /multi_threaded >zftn95NET
dbk_link2 /multi_threaded parallel_NET_DLL.dll parallel_NET_DLL.dbk >zlinkNET
ftn95 parallelDLLmain.f95 >zftn95x86
SLINK parallelDLLmain.obj parallel_NET_DLL.dll >zlinkx86
I got the error that SLINK does not find the function parallel_NET_DLL. Last thing i expected is such message which means that NET DLL is not recognized. Even compiling everything for NET by taking proper dbk_link2 instead of SLINK has the same problem. What's wrong ? Linker for NET has the problem creating readable DLL or i made some mistake somewhere?