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

[C++] Multicore coding

post #1 of 45
Thread Starter 
Right, so can someone start me off on how to code for multiple cores? Something simple to start off; how to I get the program to see how many cores are available, and then do soemthing like count to 100 million using all available cores?
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 #2 of 45
Im pretty sure you need to work with threading, which is a sub-context of concurrency. Start by creating a single main thread and off-load the work to helper threads. I dont know exactly how to do this in c++ but in java its fairly straight forward.

Edit: concurrency can get very complex with locking, locks and keys. Make sure you have a key grasp on basic and advanced concepts before you try concurrent programming, it can get tricky.
Edited by CovertCover - 12/26/10 at 2:21pm
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core i7-930 D0 3.8Ghz ASUS P6T SE PowerColor HD5870 1GB 6GB Corsair Dominator XMS3 8-8-8-20 1200Mhz 
Hard DriveOSMonitorPower
1TB Wester Digital Windows 7 Home 64bit Acer 23" XFX 850w Black Edtion 
Case
HAF 932 
  hide details  
Reply
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core i7-930 D0 3.8Ghz ASUS P6T SE PowerColor HD5870 1GB 6GB Corsair Dominator XMS3 8-8-8-20 1200Mhz 
Hard DriveOSMonitorPower
1TB Wester Digital Windows 7 Home 64bit Acer 23" XFX 850w Black Edtion 
Case
HAF 932 
  hide details  
Reply
post #3 of 45
Thread Starter 
That's sorta what I mean; how do I do that. redface.gif
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 #4 of 45
Well Im on my phone right now, if you give me a day or so i could try to wip up an example. Kinda stuck in the hospital.
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core i7-930 D0 3.8Ghz ASUS P6T SE PowerColor HD5870 1GB 6GB Corsair Dominator XMS3 8-8-8-20 1200Mhz 
Hard DriveOSMonitorPower
1TB Wester Digital Windows 7 Home 64bit Acer 23" XFX 850w Black Edtion 
Case
HAF 932 
  hide details  
Reply
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core i7-930 D0 3.8Ghz ASUS P6T SE PowerColor HD5870 1GB 6GB Corsair Dominator XMS3 8-8-8-20 1200Mhz 
Hard DriveOSMonitorPower
1TB Wester Digital Windows 7 Home 64bit Acer 23" XFX 850w Black Edtion 
Case
HAF 932 
  hide details  
Reply
post #5 of 45
Thread Starter 
I can wait. smile.gif
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 #6 of 45
Are you using C++ for any reason? A managed language like Java or C# makes it much easier to manage threads.

Realistically, you wouldn't even check to see how many cores a system has, you would assume a minimum number and code for that. The OS takes care of delegating threads to processors in time slices. Programming apps for high concurrency is not a trivial issue, there are many books written on the subject.

http://www.linuxdocs.org/HOWTOs/C++Programming-HOWTO-24.html
Mighty Mouse
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 2600k Asus P8P67-M Pro 2x470 8GB Patriot Sector 5 
Hard DriveOSMonitorKeyboard
OCZ Vertex 3 Win7 Ultimate 64 2x 30 Inch Dell Realforce 86UB 
PowerCaseMouseMouse Pad
Corsair H1000 Lian Li PC-V354 Logitech G9x Steelseries something 
  hide details  
Reply
Mighty Mouse
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 2600k Asus P8P67-M Pro 2x470 8GB Patriot Sector 5 
Hard DriveOSMonitorKeyboard
OCZ Vertex 3 Win7 Ultimate 64 2x 30 Inch Dell Realforce 86UB 
PowerCaseMouseMouse Pad
Corsair H1000 Lian Li PC-V354 Logitech G9x Steelseries something 
  hide details  
Reply
post #7 of 45
At my (former) university I took a class about this stuff, here is what they pointed me to. I'm sure there are other ways to do it, but POSIX is pretty simple.
 
HTPC
(8 items)
 
 
CPUMotherboardGraphicsRAM
i7-3930k MSI X79MA-GD45 Powercolor 7950 G Skill 
Hard DriveCoolingCoolingCooling
Samsung 830 Swiftech Apogee XT Rev. 1 EK-FC HWLabs Black Ice GTX 240 and a Koolance HX-CU72... 
CoolingCoolingOSOS
MCP 35X and a MCP 350 Koolance 401x2 Opensuse 12.1 Windows 7 
KeyboardPowerCase
Ducky OCN with cherry blues Antec True Power New 650W Cooler Master CM690 II 
CPUMotherboardGraphicsRAM
i5-750 Gigabyte p55-ud2 GTX 430 G Skill 
Hard DriveOSPowerCase
Samsung HD204UI Fedora 15 Corsair CX-430 Silverstone GC04 
  hide details  
Reply
 
HTPC
(8 items)
 
 
CPUMotherboardGraphicsRAM
i7-3930k MSI X79MA-GD45 Powercolor 7950 G Skill 
Hard DriveCoolingCoolingCooling
Samsung 830 Swiftech Apogee XT Rev. 1 EK-FC HWLabs Black Ice GTX 240 and a Koolance HX-CU72... 
CoolingCoolingOSOS
MCP 35X and a MCP 350 Koolance 401x2 Opensuse 12.1 Windows 7 
KeyboardPowerCase
Ducky OCN with cherry blues Antec True Power New 650W Cooler Master CM690 II 
CPUMotherboardGraphicsRAM
i5-750 Gigabyte p55-ud2 GTX 430 G Skill 
Hard DriveOSPowerCase
Samsung HD204UI Fedora 15 Corsair CX-430 Silverstone GC04 
  hide details  
Reply
post #8 of 45
HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\(0 - n)
You can find out how many cores the PC has based off of this registry location, not sure if that is necessary.

This seems like a pretty good start:
http://www.linuxselfhelp.com/HOWTO/C++Programming-HOWTO-18.html

I'm taking a class that teaches you this in a week, so I've not done this yet, so take what I said with a grain of salt.
post #9 of 45
Thread Starter 
Quote:
Originally Posted by avalon;11783589 
Are you using C++ for any reason? A managed language like Java or C# makes it much easier to manage threads.

Realistically, you wouldn't even check to see how many cores a system has, you would assume a minimum number and code for that. The OS takes care of delegating threads to processors in time slices. Programming apps for high concurrency is not a trivial issue, there are many books written on the subject.

http://www.linuxdocs.org/HOWTOs/C++Programming-HOWTO-24.html

I've gotta do it for Uni, so C++ is needed. tongue.gif
Quote:
Originally Posted by mdatmo;11783641 
At my (former) university I took a class about this stuff, here is what they pointed me to. I'm sure there are other ways to do it, but POSIX is pretty simple.

Where do I get pthread.h? I downloaded one, but I get linker errors.
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 #10 of 45
Thread Starter 
Quote:
Originally Posted by hoth17;11783699 
HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\(0 - n)
You can find out how many cores the PC has based off of this registry location, not sure if that is necessary.

And how do I call that location?
Quote:
Originally Posted by hoth17;11783699 
This seems like a pretty good start:
http://www.linuxselfhelp.com/HOWTO/C++Programming-HOWTO-18.html

I'm taking a class that teaches you this in a week, so I've not done this yet, so take what I said with a grain of salt.

Tried the code on that website; ran into loads of errors...

That seems to be my main problem; finding a sample of code that actually runs...
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