Multicore processing

This forum is for eXpress++ general support.
Message
Author
User avatar
rdonnay
Site Admin
Posts: 4734
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Multicore processing

#11 Post by rdonnay »

Add the following code to the start of your program:

DC_SetCPU()

Code: Select all

FUNCTION DC_SetCPU( nCPU, cFile )

LOCAL nHnd  := 0                             // file handle
LOCAL nLast := 1                             // last CPU used
LOCAL aSet  := {}                            // processor array
LOCAL nSet                                   // default new bitmask
LOCAL i                                      // counter

DEFAULT cFile := GetEnv('WINDIR') + '\Temp\SetCpu.Smp'

DEFAULT nCPU := 15
// 15 = 4 CPUs
//  7 = 3 CPUs
//  3 = 2 CPUs
//  1 = 1 CPU

nSet := nCPU

FOR i := 1 to 32                             // count processors
   IF nCPU[i]                                // processor present
      aadd(aSet, i)                          // add processor id to list
   ENDIF
NEXT

IF len(aSet) > 1                             // more then one processor
   IF Fexists(cFile)
      nHnd := Fopen(cFile, FO_READWRITE)
      IF nHnd > 0                            // file is open
         nLast := Val(Freadstr(nHnd, 2))+ 1  // get last processor
         IF nLast > len(aSet)                // check against available processors
            nLast := 1                       // recycle number
         ENDIF
         Fseek(nHnd, 0, FS_SET)              // place pointer at bof
         Fwrite(nHnd, StrZero(nLast, 2))     // write to file
         Fclose(nHnd)                        // close file
      ENDIF
   ELSE                                      // first time round
      nHnd := Fcreate(cFile, FC_NORMAL)
      IF nHnd > 0                            // file is created and open
         Fwrite(nHnd, StrZero(nLast, 2))     // write to file
         Fclose(nHnd)                        // close file
      ENDIF
   ENDIF

   FOR i := 1 to 32                          // create new bitmask
      nSet[i] := (i = aSet[nLast])           // switch on appropriate bit
   NEXT

   DllCall("xpprt1.dll", DLL_CDECL, "_sysSetCPU", nSet)

ENDIF

RETURN nil
The eXpress train is coming - and it has more cars.

omni
Posts: 534
Joined: Thu Jan 28, 2010 9:34 am

Re: Multicore processing

#12 Post by omni »

Roger,


thanks.

I have heard differently, so that is the start of the program called from the menu, or at the top of the main menu when the user starts our exe. I think its when we call the program from the menu, but want to be sure before I actually test it on the users server since its 'threads' And if its the program, before we call newthread ?. Hope my questions are not too stupid but this core assignment is new to me.

I read in the docs to put it at the top of the Main program, assume that means at the top when we open the exe, first line after the ch files, etc.

Will try that and open it 3 times to see what happens


Opened our app 3 times and opened task manager. All show on core 0. Moved to save the file on the server so it could be easily checked and it shows changing the core to be used like it is supposed to. Am I doing something wrong, or missing a step? Or is the dllcall just not working?

OK, never mind. The task manager show core 0, but the set affinity does show the different cpu's like it should...good job.

Thanks

Fred

User avatar
Auge_Ohr
Posts: 1414
Joined: Wed Feb 24, 2010 3:44 pm

Re: Multicore processing

#13 Post by Auge_Ohr »

unixkd wrote:Please post the code for the "switchcpu" function.
it is the same as DC_SetCPU() but as you can see i "switch" it every 0.1Sec.

Code: Select all

FUNCTION switchcpu(nMax)
LOCAL nWorkCPU
LOCAL nStep

DEFAULT nMax TO 1

   nStep := RandomInt(1,nMax)
   IF nStep = 1
      SmpSetCPU(1)
   ELSE
      nWorkCPU  := 2 ^INT(nStep-1)

      IF SmpSetCPU(nWorkCPU) = 0
         SmpSetCPU(1)
      ENDIF
   ENDIF
   nWorkCPU := SmpGetCPU()

*** show output

   GraSetColor(,GRA_CLR_WHITE)
   GraStringAt(,{0,0},"CPU :     " )
   IF nStep > 0 .AND. nStep <= 15
      GraSetColor(,nStep)
   ELSE
      GraSetColor(,GRA_CLR_BLACK)
   ENDIF
   GraStringAt(,{0,0},"CPU : " + POT2DEC(nWorkCPU) )

RETURN nStep


greetings by OHR
Jimmy

User avatar
Eugene Lutsenko
Posts: 1649
Joined: Sat Feb 04, 2012 2:23 am
Location: Russia, Southern federal district, city of Krasnodar
Contact:

Re: Multicore processing

#14 Post by Eugene Lutsenko »

All of this is extremely interesting ! Determining whether the core function of demand is : nCPU (), the function assignment of the process to the kernel DC_SetCPU () also is. Is there a function that determines the degree of congestion of the nucleus? It would be interesting to use the LPT algorithm for the management of scheduled tasks , depending on the length of the vacated core. I would be very interested in simple examples of the distribution of tasks between cores. The algorithms that I use , allow a very efficient parallelization , as if they are specially created for it ( they are largely due to the processing of matrices )

User avatar
Eugene Lutsenko
Posts: 1649
Joined: Sat Feb 04, 2012 2:23 am
Location: Russia, Southern federal district, city of Krasnodar
Contact:

Re: Multicore processing

#15 Post by Eugene Lutsenko »

How to programmatically identify:
- Which exist in the processor core?
- How much is loaded or that the nucleus?
Auge_Ohr wrote:hi,

Xbase++ will ALLWAYS work on 1 CPU and all Thread are working on same.
but you can switch CPU every 0.1 sec NOT getting more Power but CPU can "cool down" not used CPU
here is an Example which use all you CPU with < 100 %

Code: Select all

   oTimer := Thread():new()
   oTimer:setInterval(10)
   oTimer:start("switchcpu",nMaxCPU)
here some Demo ( look into you Taskmanager -> CPU ) how different it will use CPU
MoreCPU_Demo.zip
And could you give me the source code of these examples? Please...

User avatar
Auge_Ohr
Posts: 1414
Joined: Wed Feb 24, 2010 3:44 pm

Re: Multicore processing

#16 Post by Auge_Ohr »

Eugene Lutsenko wrote:And could you give me the source code of these examples? Please...
you will find Source of SMP in c:\ALASKA\XPPW32\Source\samples\solution\smp\smprun.prg
Eugene Lutsenko wrote:- Which exist in the processor core?

Code: Select all

FUNCTION CHECKMaxCPU()
LOCAL nStep
LOCAL nMaxCPU

   nStep := 1
   DO WHILE .T.
      nMaxCPU = 2 ^nStep
      IF SmpSetCPU(nMaxCPU) = 0
         EXIT
      ENDIF
      nStep++
   ENDDO

   GraSetColor(,GRA_CLR_BLACK)
   GraStringAt(,{0,0},"Anwendung läuft auf max. : " + var2char(nStep) + " CPUs" )

RETURN nStep
Eugene Lutsenko wrote: - How much is loaded or that the nucleus?
this is total different to SMP.

search for "Performance Data Helper" (PDH) DLL from Mircosoft.
SYSMON.OCX can not be used with Xbase++ while not from IDispatch ...

but remember
Auge_Ohr wrote:Xbase++ will ALLWAYS work on 1 CPU and all Thread are working on same.
i do switch CPU to other NOT for Performance !
it is while my i7-2630QM Cooler make Noise when Xbase++ use 100% of 1 CPU and other 7 are sleeping ...

Note : when using activeX you have to increase Time between switch CPU else send/receive Events may delay.
greetings by OHR
Jimmy

User avatar
Eugene Lutsenko
Posts: 1649
Joined: Sat Feb 04, 2012 2:23 am
Location: Russia, Southern federal district, city of Krasnodar
Contact:

Re: Multicore processing

#17 Post by Eugene Lutsenko »

This example, which in the beginning I have seen.
And what if the core switch, if not to improve the overall performance?

User avatar
Auge_Ohr
Posts: 1414
Joined: Wed Feb 24, 2010 3:44 pm

Re: Multicore processing

#18 Post by Auge_Ohr »

Eugene Lutsenko wrote:And what if the core switch, if not to improve the overall performance?
as i say
it is while my i7-2630QM Cooler make Noise when Xbase++ use 100% of 1 CPU and other 7 are sleeping ...
when run Demo MoreCPU3.EXE it will never reach 100% when switch CPU before it get real hot ( and begin to change FSB ) so Cooler does not make Noise ;)

if you use a Terminal Server than you can assign each Client Application to a Different CPU.
if you have 8 Core you can start your Xbase++ Application 8 times each on other CPU.
greetings by OHR
Jimmy

User avatar
Auge_Ohr
Posts: 1414
Joined: Wed Feb 24, 2010 3:44 pm

Re: Multicore processing

#19 Post by Auge_Ohr »

Auge_Ohr wrote:SYSMON.OCX can not be used with Xbase++ while not from IDispatch ...
hm ... something have change in 6.3.9600.16407 which come with Windows v8.1 ... now Sample begin to work ...
greetings by OHR
Jimmy

User avatar
Tom
Posts: 1176
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: Multicore processing

#20 Post by Tom »

PDH is useless. What you get (if it works, this is a big maybe) is a snapshot. However, the CPU usage may change within the next millisecond. If an app tries to retrieve the PDH data (which comes from phantom registry values) every millisecond, it creates CPU workload. On the other side, a standard business application simply does nothing most of the time. It waits for data entry, for example. If you track the CPU workload created by your app, you will find out that there is almost nothing. The processes creating CPU workload are complex screen outputs (lots of controls) and some kind of statistics. Even if heavy data is processed, the bottleneck are network adaptors and/or mass storages. This will not get any faster if the CPU is switched.

The best way is to randomly select a CPU. In addition, an app may provide an option to switch the CPU from inside the app. If our app runs on a Terminal Server, we collect the processors used (in a table) and show the CPU usage (amount of users running on each CPU). If a user wants, he can switch. That's it.
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

Post Reply