Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › [C++] Multicore coding
New Posts  All Forums:Forum Nav:

[C++] Multicore coding - Page 3

post #21 of 45
HANDLE Thread_2 = CreateThread(0, 0, ThreadFn, &uiCounter, 0, &qThreadID);
That is the name of the function which controls your thread, so you must make a new function and function prototype for the new thread.

DWORD WINAPI ThreadFn1(LPVOID vpParam); //prototype
HANDLE Thread_1 = CreateThread(0, 0, ThreadFn1, &uiCounter, 0, &qThreadID); //declaration
DWORD WINAPI ThreadFn1(LPVOID vpParam) //header

edit: what do you mean show which thread it is?
Edited by hoth17 - 12/27/10 at 12:51pm
post #22 of 45
You really need to stop coding and go back to read fundamentals. Multi-threading is not a simple thing that you can just learn by writing code. There are different techniques, concepts, strategies, and issues to learn first.

The output of code can always end up different so it would take a really long time to debug.
Once again...
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 920 [4.28GHz, HT] Asus P6T + Broadcom NetXtreme II VisionTek HD5850 [900/1200] + Galaxy GT240 2x4GB G.Skill Ripjaw X [1632 MHz] 
Hard DriveOSMonitorKeyboard
Intel X25-M 160GB + 3xRAID0 500GB 7200.12 Window 7 Pro 64 Acer H243H + Samsung 226BW XARMOR-U9BL  
PowerCaseMouseMouse Pad
Antec Truepower New 750W Li Lian PC-V2100 [10x120mm fans] Logitech G9 X-Trac Pro 
  hide details  
Reply
Once again...
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 920 [4.28GHz, HT] Asus P6T + Broadcom NetXtreme II VisionTek HD5850 [900/1200] + Galaxy GT240 2x4GB G.Skill Ripjaw X [1632 MHz] 
Hard DriveOSMonitorKeyboard
Intel X25-M 160GB + 3xRAID0 500GB 7200.12 Window 7 Pro 64 Acer H243H + Samsung 226BW XARMOR-U9BL  
PowerCaseMouseMouse Pad
Antec Truepower New 750W Li Lian PC-V2100 [10x120mm fans] Logitech G9 X-Trac Pro 
  hide details  
Reply
post #23 of 45
Quote:
Originally Posted by DuckieHo View Post
The output of code can always end up different so it would take a really long time to debug.
When you say always end up different, you mean due to the lack of locks?
post #24 of 45
Thread Starter 
Quote:
Originally Posted by hoth17 View Post
HANDLE Thread_2 = CreateThread(0, 0, ThreadFn, &uiCounter, 0, &qThreadID);
That is the name of the function which controls your thread, so you must make a new function and function prototype for the new thread.

DWORD WINAPI ThreadFn1(LPVOID vpParam); //prototype
HANDLE Thread_1 = CreateThread(0, 0, ThreadFn1, &uiCounter, 0, &qThreadID); //declaration
DWORD WINAPI ThreadFn1(LPVOID vpParam) //header

edit: what do you mean show which thread it is?
That makes more sense... I'll give that a try.

Quote:
Originally Posted by DuckieHo View Post
You really need to stop coding and go back to read fundamentals. Multi-threading is not a simple thing that you can just learn by writing code. There are different techniques, concepts, strategies, and issues to learn first.

The output of code can always end up different so it would take a really long time to debug.
If I had something to read, I would. But my book doesn't cover mulitcore coding... and we've not really done any work on it in our lectures either...

So I thought I'd come here and look for someone to explain it simply to me. I know more than I did this time yesterday though, so if I keep up at that rate, I'll get it eventually.

Anyway... off to go try some more.
Megadoomer
(14 items)
 
Family Computer
(13 items)
 
 
CPUMotherboardGraphicsRAM
Phenom II X6 1090T @ 4.0Ghz ASUS M4A89GTD PRO Sparkle GTS 450 2x4GB G-Skill Sniper 
Hard DriveCoolingOSMonitor
Samsung F1 1TB CM Hyper 212+ Windows 7 Professional x64 Samsung T220 
KeyboardPowerCaseMouse
Logitech MX3000 Laser CM 1000M HAF 922 Logitech VX Revolution 
CPUMotherboardGraphicsRAM
Q6600 Asus PN5-D 750i Evga GTS 250 2x2GB Crucial Ballistix 
Hard DriveOptical DriveOSMonitor
750GB Hitachi Samsung Super Writemaster Windows 7 Professional x64 19" Dell 
PowerCase
Corsair 450VX Antec 900 
  hide details  
Reply
Megadoomer
(14 items)
 
Family Computer
(13 items)
 
 
CPUMotherboardGraphicsRAM
Phenom II X6 1090T @ 4.0Ghz ASUS M4A89GTD PRO Sparkle GTS 450 2x4GB G-Skill Sniper 
Hard DriveCoolingOSMonitor
Samsung F1 1TB CM Hyper 212+ Windows 7 Professional x64 Samsung T220 
KeyboardPowerCaseMouse
Logitech MX3000 Laser CM 1000M HAF 922 Logitech VX Revolution 
CPUMotherboardGraphicsRAM
Q6600 Asus PN5-D 750i Evga GTS 250 2x2GB Crucial Ballistix 
Hard DriveOptical DriveOSMonitor
750GB Hitachi Samsung Super Writemaster Windows 7 Professional x64 19" Dell 
PowerCase
Corsair 450VX Antec 900 
  hide details  
Reply
post #25 of 45
Are we talking about multi-thread or multi-core programming here? Simply put, try my best, multi-thread programming usually refers to max utilize single core to do more work so cpu isn't in idle stage as possible. Multi-core programming refers to package work and spread them on cores so get thing done quickly. Most languages should have built-in management object to simplify the multi-thread process. On the other hand, multi-core programming is more complicated because you need to split work, maintain state dependencies and keep tracking of resource usage etc. Principle may be same but chip marker like Intel should have tools to help developer to simplify this. In real world, it can be mix of multi-threaded and multi-core program because of the nature of task, and most latest processor packaged with multi cores and each provides hyper threading. It seems to me that code above looks like to create multi threads to me. Again, I try my best to explain.
post #26 of 45
Thread Starter 
Here's exactly what I'm meant to be doing:

• Write a worker procedure that, until told to stop, continually transfers a random amount of money from one random account to another random account.
• Create multiple threads, each running the worker procedure.
• Run for N seconds.
• Check that the balance for the bank as a whole doesn't change.
• Measure how many transactions per second can be performed as the number of threads is increased.

But since I don't actually know how to use multiple threads, I wanted to get some sort of basis before I tried it out.
Megadoomer
(14 items)
 
Family Computer
(13 items)
 
 
CPUMotherboardGraphicsRAM
Phenom II X6 1090T @ 4.0Ghz ASUS M4A89GTD PRO Sparkle GTS 450 2x4GB G-Skill Sniper 
Hard DriveCoolingOSMonitor
Samsung F1 1TB CM Hyper 212+ Windows 7 Professional x64 Samsung T220 
KeyboardPowerCaseMouse
Logitech MX3000 Laser CM 1000M HAF 922 Logitech VX Revolution 
CPUMotherboardGraphicsRAM
Q6600 Asus PN5-D 750i Evga GTS 250 2x2GB Crucial Ballistix 
Hard DriveOptical DriveOSMonitor
750GB Hitachi Samsung Super Writemaster Windows 7 Professional x64 19" Dell 
PowerCase
Corsair 450VX Antec 900 
  hide details  
Reply
Megadoomer
(14 items)
 
Family Computer
(13 items)
 
 
CPUMotherboardGraphicsRAM
Phenom II X6 1090T @ 4.0Ghz ASUS M4A89GTD PRO Sparkle GTS 450 2x4GB G-Skill Sniper 
Hard DriveCoolingOSMonitor
Samsung F1 1TB CM Hyper 212+ Windows 7 Professional x64 Samsung T220 
KeyboardPowerCaseMouse
Logitech MX3000 Laser CM 1000M HAF 922 Logitech VX Revolution 
CPUMotherboardGraphicsRAM
Q6600 Asus PN5-D 750i Evga GTS 250 2x2GB Crucial Ballistix 
Hard DriveOptical DriveOSMonitor
750GB Hitachi Samsung Super Writemaster Windows 7 Professional x64 19" Dell 
PowerCase
Corsair 450VX Antec 900 
  hide details  
Reply
post #27 of 45
Quote:
Originally Posted by zodac View Post
Here's exactly what I'm meant to be doing:

• Write a worker procedure that, until told to stop, continually transfers a random amount of money from one random account to another random account.
• Create multiple threads, each running the worker procedure.
• Run for N seconds.
• Check that the balance for the bank as a whole doesn't change.
• Measure how many transactions per second can be performed as the number of threads is increased.

But since I don't actually know how to use multiple threads, I wanted to get some sort of basis before I tried it out.
I think all that folding knowledge of yours is clouding the exercise here. Your focus should simply be on creating a thread-safe work function, a method of synchronization, and spinning up the threads. It's the operating system's job to determine how many cores to use and which threads to run on any given processor.
TheHydra
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 860 @ 3.6 EVGA P55 FTW Sapphire TOXIC 2GB 6950 CORSAIR XMS3 4 x 2GB CMX4GX3M2A1600C7 
Hard DriveOSKeyboardPower
C300 64Gb + 2x F3 HD103SJ 1TB in RAID 0 Win7 x64 Razer BlackWidow Corsair 750HX 
CaseMouseMouse Pad
Lian Li A05NB with 140mm top fan. Razer DeathAdder Razer Kabuto 
  hide details  
Reply
TheHydra
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 860 @ 3.6 EVGA P55 FTW Sapphire TOXIC 2GB 6950 CORSAIR XMS3 4 x 2GB CMX4GX3M2A1600C7 
Hard DriveOSKeyboardPower
C300 64Gb + 2x F3 HD103SJ 1TB in RAID 0 Win7 x64 Razer BlackWidow Corsair 750HX 
CaseMouseMouse Pad
Lian Li A05NB with 140mm top fan. Razer DeathAdder Razer Kabuto 
  hide details  
Reply
post #28 of 45
Thread Starter 
Well, I do need to find out how many cores I have available, don't I? So I can tell the program to run on that many cores, or on one less than max, etc?

And I don't mind which thread runs; I'd like to have it say which thread is actually running that the time (though this is just because I wanna see how it works, not because I need it).
Megadoomer
(14 items)
 
Family Computer
(13 items)
 
 
CPUMotherboardGraphicsRAM
Phenom II X6 1090T @ 4.0Ghz ASUS M4A89GTD PRO Sparkle GTS 450 2x4GB G-Skill Sniper 
Hard DriveCoolingOSMonitor
Samsung F1 1TB CM Hyper 212+ Windows 7 Professional x64 Samsung T220 
KeyboardPowerCaseMouse
Logitech MX3000 Laser CM 1000M HAF 922 Logitech VX Revolution 
CPUMotherboardGraphicsRAM
Q6600 Asus PN5-D 750i Evga GTS 250 2x2GB Crucial Ballistix 
Hard DriveOptical DriveOSMonitor
750GB Hitachi Samsung Super Writemaster Windows 7 Professional x64 19" Dell 
PowerCase
Corsair 450VX Antec 900 
  hide details  
Reply
Megadoomer
(14 items)
 
Family Computer
(13 items)
 
 
CPUMotherboardGraphicsRAM
Phenom II X6 1090T @ 4.0Ghz ASUS M4A89GTD PRO Sparkle GTS 450 2x4GB G-Skill Sniper 
Hard DriveCoolingOSMonitor
Samsung F1 1TB CM Hyper 212+ Windows 7 Professional x64 Samsung T220 
KeyboardPowerCaseMouse
Logitech MX3000 Laser CM 1000M HAF 922 Logitech VX Revolution 
CPUMotherboardGraphicsRAM
Q6600 Asus PN5-D 750i Evga GTS 250 2x2GB Crucial Ballistix 
Hard DriveOptical DriveOSMonitor
750GB Hitachi Samsung Super Writemaster Windows 7 Professional x64 19" Dell 
PowerCase
Corsair 450VX Antec 900 
  hide details  
Reply
post #29 of 45
Quote:
Originally Posted by zodac View Post
Well, I do need to find out how many cores I have available, don't I? So I can tell the program to run on that many cores, or on one less than max, etc?

And I don't mind which thread runs; I'd like to have it say which thread is actually running that the time (though this is just because I wanna see how it works, not because I need it).
I don't think you do.

Quote:
Originally Posted by zodac;
Measure how many transactions per second can be performed as the number of threads is increased.
This point from your problem statement makes me think you're meant to set the number of threads used as a parameter. The OS will do its best to service the threads you've spun up, whatever the number.

The interesting part of playing with this will be finding for which number of threads you get peak performance. It's rarely as simple as #threads = #cores. It's not terribly interesting on a single core machine, but determining the peak number of worker processes gets to be more and more like black magic the more resources you have to throw around and the more complex your work function.

This kind of stuff is when that CS degree starts getting fun
TheHydra
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 860 @ 3.6 EVGA P55 FTW Sapphire TOXIC 2GB 6950 CORSAIR XMS3 4 x 2GB CMX4GX3M2A1600C7 
Hard DriveOSKeyboardPower
C300 64Gb + 2x F3 HD103SJ 1TB in RAID 0 Win7 x64 Razer BlackWidow Corsair 750HX 
CaseMouseMouse Pad
Lian Li A05NB with 140mm top fan. Razer DeathAdder Razer Kabuto 
  hide details  
Reply
TheHydra
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 860 @ 3.6 EVGA P55 FTW Sapphire TOXIC 2GB 6950 CORSAIR XMS3 4 x 2GB CMX4GX3M2A1600C7 
Hard DriveOSKeyboardPower
C300 64Gb + 2x F3 HD103SJ 1TB in RAID 0 Win7 x64 Razer BlackWidow Corsair 750HX 
CaseMouseMouse Pad
Lian Li A05NB with 140mm top fan. Razer DeathAdder Razer Kabuto 
  hide details  
Reply
post #30 of 45
Thread Starter 
Sorry, I never added this comment:
"Given a PC with N cores (CPUs), count the total number of transactions per second performed with 1 to 2*N threads."

My take on that is start at 1 and continue to the max.
Megadoomer
(14 items)
 
Family Computer
(13 items)
 
 
CPUMotherboardGraphicsRAM
Phenom II X6 1090T @ 4.0Ghz ASUS M4A89GTD PRO Sparkle GTS 450 2x4GB G-Skill Sniper 
Hard DriveCoolingOSMonitor
Samsung F1 1TB CM Hyper 212+ Windows 7 Professional x64 Samsung T220 
KeyboardPowerCaseMouse
Logitech MX3000 Laser CM 1000M HAF 922 Logitech VX Revolution 
CPUMotherboardGraphicsRAM
Q6600 Asus PN5-D 750i Evga GTS 250 2x2GB Crucial Ballistix 
Hard DriveOptical DriveOSMonitor
750GB Hitachi Samsung Super Writemaster Windows 7 Professional x64 19" Dell 
PowerCase
Corsair 450VX Antec 900 
  hide details  
Reply
Megadoomer
(14 items)
 
Family Computer
(13 items)
 
 
CPUMotherboardGraphicsRAM
Phenom II X6 1090T @ 4.0Ghz ASUS M4A89GTD PRO Sparkle GTS 450 2x4GB G-Skill Sniper 
Hard DriveCoolingOSMonitor
Samsung F1 1TB CM Hyper 212+ Windows 7 Professional x64 Samsung T220 
KeyboardPowerCaseMouse
Logitech MX3000 Laser CM 1000M HAF 922 Logitech VX Revolution 
CPUMotherboardGraphicsRAM
Q6600 Asus PN5-D 750i Evga GTS 250 2x2GB Crucial Ballistix 
Hard DriveOptical DriveOSMonitor
750GB Hitachi Samsung Super Writemaster Windows 7 Professional x64 19" Dell 
PowerCase
Corsair 450VX Antec 900 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › [C++] Multicore coding