forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Shortest example of multithreaded run with FTN95

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
DanRRight



Joined: 10 Mar 2008
Posts: 2124
Location: South Pole, Antarctica

PostPosted: Wed Jul 16, 2008 12:44 pm    Post subject: Shortest example of multithreaded run with FTN95 Reply with quote

How will look in FTN95 absolutely simplest and shortest program which will launch two separate subroutines in two threads, say, ones emulating long run? Emulating programs could look like this

integer function run1()
a=2.0
do i=1,10000000
a=alog(exp(a))
enddo
run1=1
end
Back to top
View user's profile Send private message
DanRRight



Joined: 10 Mar 2008
Posts: 2124
Location: South Pole, Antarctica

PostPosted: Sat Jul 19, 2008 7:52 am    Post subject: Reply with quote



Last edited by DanRRight on Sat Jul 19, 2008 10:31 am; edited 1 time in total
Back to top
View user's profile Send private message
DanRRight



Joined: 10 Mar 2008
Posts: 2124
Location: South Pole, Antarctica

PostPosted: Sat Jul 19, 2008 10:30 am    Post subject: Re: Reply with quote

OK, what I'd like to see is the following. Here is the shortest code which I'd like to be working in FTN95. Unfortunately it does not open another thread if you click on tab 2 after clicking on tab 1.

What it is unfortunately doing, it stops for a while execution of the function run1 when you click 2 and starts run2, when run2 finishes, run1 continues. You can see that if you open Task Manager on your multicore PC. If there would be multithreading then two cores would start the tasks independently grabbing 100% CPU time

Multithreading is the simplest way of doing simulations in parallel. We can for example devide some long running DO loop this way into deviding it to two parts and run both parts on separate threads, hence numerous cores will be improving execution speed by factor 2, 4 or 8 or N times depending on amount of your cores.

It can be done with .NET as shows FTN95 Threads example, but it is kind of cumbersome. Can it be done without .NET ? .NET in current version is the complication without simplification eye candies. Most of people do not like to know even Clearwin+, which is great, so there is no way they will like the next level of complexity. Fortran lives 50+ years because it is simplicity (and due to that speed) up to ultimate stupidity. Salford/Silverfrost fortran is unique in the sense that it is the only one which can offer us the so called "click programming" for each and everyone because it has build-in GUI builder (Clearwin+, Visual Clearwin). I'm not a visionary by any means, but IMHO time is gone for complex line-by-line programming like it is gone for lineprinters. Also IMHO everyone would use .NET if all applications were assembled by mouse clicks. Is this how it is done now using Visual Studio? This "visual studio" is not a real visual studio I'd like to see

Code:
   use clrwin
   integer  run1, run2
   external run1, run2

   i=winio@('%ww&')
   i=winio@('%^tt[1]%ff&', run1)
   i=winio@('%ac[Esc]&','exit')
   i=winio@('%ac[Ctrl+1]&',run1)
   i=winio@('%ac[Ctrl+2]&',run2)
   i=winio@('%^tt[2]', run2)
   end

!----------------------
integer function run1()
   use clrwin
   print*,'1 is running'
   CALL PERMIT_ANOTHER_callback@()
   a=2.0
   do k=1,50
   call temporary_yield@()
   do i=1,10000000
   a=alog(exp(a))
   enddo
   enddo
   print*,'1 ended'
   run1=1
end
!----------------------
integer function run2()
   use clrwin
   print*,'2 is running'
   a=2.0
   do k=1,50
   call temporary_yield@()
   do i=1,10000000
   a=alog(exp(a))
   enddo
   enddo
   print*,'2 ended'
   run2=1
end
Back to top
View user's profile Send private message
DanRRight



Joined: 10 Mar 2008
Posts: 2124
Location: South Pole, Antarctica

PostPosted: Wed Jul 23, 2008 10:02 am    Post subject: Reply with quote

With this respect there was some real life experience anecdot.
Professor asking students:
-"Do you know how integrate this kind of functions?". Total silence. Then he asked :
-"Did you know how integrate this kind of functions?". Silence again. Then he asked next approximation question:
-"At the time of exam last year did you you know how integrate this kind of functions?". Student again sitting still, and no one responds. Finally he asks:
-"Did you have to know at the time of exam last year how integrate this kind of functions?". And the answer finally was yes Sad

OK, even simplesr question. I am confused do we need for FTN95 multithreading code all that threads.ftn95p, THREADS.SLN, THREADS.suo files (found in the Examples directory) containing something like this (or even binary) which I have no clue what relationship have to the Fortran:

"General"
{
"ProjectIdGuid" = "{6025DA35-1FE6-45F1-B0A4-889176813D25}"
}
"Configurations"
{
"Debug|Win32"
{
"Windows" = "Yes"
"SealedClass" = "Yes"
"ContainingClass" = ""
"Version" = ""
"Stack_NET" = ""
"Map" = ""
"Silent" = "No"
"Base" = ""
"Exportall" = "No"
"Heap" = ""
"MultiThreaded" = "No"
"Extras" = ""
"VirtualCommon" = ""
"InterfaceOnly" = "No"
"NoLink" = "No"
"DebugInfo" = "Yes"
"Check" = "No"
"Undef" = "No"
"CheckMate" = "No"
"FullDebug" = "No"
"BoundsCheck" = "No"
"DebugSource" = "No"
"Overflow" = "No"
"Profile" = "No"
"QuickBounds" = "No"
"Runtrace" = "No"
"SuppressArgCheck" = "No"
"Timing" = "No"
"Underflow" = "No"
"Optimise" = "No"
"P6" = "Yes"
"UnrollLimit" = ""


or

Microsoft Visual Studio Solution File, Format Version 8.00
Project("{FDDF9C0B-7F1F-454F-BCAE-4B4E5ACCE74A}") = "Threads", "Threads.ftn95p", "{6025DA35-1FE6-45F1-B0A4-889176813D25}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
CheckMate .NET = CheckMate .NET
CheckMate Win32 = CheckMate Win32
Release .NET = Release .NET
Release Win32 = Release Win32
EndGlobalSection
GlobalSection(ProjectConfiguration) = postSolution
{6025DA35-1FE6-45F1-B0A4-889176813D25}.CheckMate .NET.ActiveCfg = CheckMate|.NET
{6025DA35-1FE6-45F1-B0A4-889176813D25}.CheckMate .NET.Build.0 = CheckMate|.NET
{6025DA35-1FE6-45F1-B0A4-889176813D25}.CheckMate Win32.ActiveCfg = CheckMate|Win32
{6025DA35-1FE6-45F1-B0A4-889176813D25}.CheckMate Win32.Build.0 = CheckMate|Win32

Are those FTN95 settings just for Microsoft Dev Studio and are they needed if we do not use MS Dev Studio?

And what is this assembly_external in the header:

........
include <clearwin.ins>
assembly_external (name="System.Threading.Thread.Sleep") thread_sleep
data num_iterations/500/
.......

or "object" here

integer function start_thread1()
use thread_control
external thread_proc
object ("System.Threading.Thread") threadObject
.............
Back to top
View user's profile Send private message
DanRRight



Joined: 10 Mar 2008
Posts: 2124
Location: South Pole, Antarctica

PostPosted: Fri Jul 25, 2008 8:44 am    Post subject: Reply with quote

This is what I approximately wanted, though it is not shortest example Smile...Compilation:
ftn95 mult01.FOR /clr /link /free /multi_threaded
A lot of such examples must be included into Demo...
Code:
! Multithreading example mult01.for
! Dan R Right 2008
!
! Watch in Task Manager how two sub run1 and run2
! will grab two processors CPU time,
! essentially working in parallel
!
! Compilation: ftn95 mult01.FOR /clr /link /free /multi_threaded
!
include <clearwin.ins>
EXTERNAL run1, run2

CALL CREATE_THREAD@(run1,42)
CALL CREATE_THREAD@(run2,43)

END
!----------------
subroutine run1()
   include <clearwin.ins>
   lock;   print*,'Thr.1 started'; end lock
   a=2.0
   do k=1,30
   do i=1,10000000
   a=alog(exp(a))
   enddo
   enddo
   lock;   print*,'Thr.1 ended' ; end lock
end
!----------------
subroutine run2()
   include <clearwin.ins>
   lock;   print*,'Thr.2 started' ;end lock
   a=2.0
   do k=1,40
   do i=1,10000000
   a=alog(exp(a))
   enddo
   enddo
   lock;   print*,'Thr.2 ended' ;end lock
end


Last edited by DanRRight on Thu May 10, 2012 1:55 pm; edited 1 time in total
Back to top
View user's profile Send private message
Andrew



Joined: 09 Sep 2004
Posts: 232
Location: Frankfurt, Germany

PostPosted: Fri Jul 25, 2008 10:51 am    Post subject: Reply with quote

In your previous post all of those settings were project related to VS. The statements you do not recognise are .NET extensions.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group