473,659 Members | 2,934 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multicore-programming?

cnb
If I buy a multicore computer and I have really intensive program. How
would that be distributed across the cores?

Will algorithms always have to be programmed and told specifically to
run on several cores so if not told it will only utilize one core?

So is the free lunch really over or is this just an overhyped
phenomena?

Is threading with Python hard? Can you start several processes with
Python or just threads?
Sep 6 '08 #1
6 2585


cnb wrote:
If I buy a multicore computer and I have really intensive program. How
would that be distributed across the cores?

Will algorithms always have to be programmed and told specifically to
run on several cores so if not told it will only utilize one core?
I believe that has always been true.
>
So is the free lunch really over or is this just an overhyped
phenomena?

Is threading with Python hard?
Opinions vary, mostly depending on experience. But Python threads do
not distribute across processors.
>Can you start several processes with
Python or just threads?
import subprocess
and read the manual for that module

Sep 6 '08 #2
On 7 Sep, 00:06, cnb <circularf...@y ahoo.sewrote:
If I buy a multicore computer and I have really intensive program. How
would that be distributed across the cores?
It typically depends on how the work done by the program is performed.
Will algorithms always have to be programmed and told specifically to
run on several cores so if not told it will only utilize one core?
Some algorithms lend themselves to parallelisation ; others do not.
Sometimes tools and runtimes can help by executing some instructions
in parallel.
So is the free lunch really over or is this just an overhyped
phenomena?
The free lunch ended a few minutes ago. ;-)
Is threading with Python hard? Can you start several processes with
Python or just threads?
You can start both processes and threads with Python, although the
effect of starting many threads - the actual concurrency - will depend
on which implementation of Python you're using and where the bulk of
the work is performed.

If you're spending a lot of CPU time in processing data, and if that
processing is taking place in Python code, then for the most effective
threading you should consider an implementation like Jython or
IronPython which supports free-threading. If most of the work happens
in extension code (where you'd probably have little choice about using
CPython, anyway), then it might be the case that the extension
releases the global interpreter lock in CPython and you might then be
able to benefit from having many threads doing work simultaneously,
although I imagine that the extension would itself need to be thread-
safe, too.

If you're spending a lot of time moving data around, performing
communication, and so on, then multiple threads may still be effective
in CPython, since some of them might be getting a system call to read
or write data, thus freeing the CPU for the others. These kinds of
situations lend themselves to other approaches such as asynchronous
processing of data, however. It doesn't sound like this is like your
program, if by "intensive" you mean high levels of CPU activity.

As you note, the alternative to threads is processes, and many people
advocate multi-process, "shared nothing" solutions. Here's a list
which covers multicore and SMP-related solutions as well as high-end
clustering solutions:

http://wiki.python.org/moin/ParallelProcessing

Although the processing module is part of Python 2.6/3.0 as the
multiprocessing module, you might want to at least look at the pp,
pprocess and papyros solutions. My aim with pprocess was to target
multicore UNIX-like systems with an unintrusive API; pp and papyros,
on the other hand, seek to cover larger scale systems as well, and I
think that the way papyros has been done has some merit, mostly
because if you wanted to combine convenience with distributed
processing, you'd want to choose distributed object technologies as
the foundation (CORBA would have been good for this, too, at least for
multi-language support, but its APIs can also seem quite
intimidating).

Paul
Sep 6 '08 #3
On Sep 7, 8:06*am, cnb <circularf...@y ahoo.sewrote:
If I buy a multicore computer and I have really intensive program. How
would that be distributed across the cores?
AFAIK, a single process wouldn't be distributed automatically.
Will algorithms always have to be programmed and told specifically to
run on several cores so if not told it will only utilize one core?
AFAIK, yes. See (for example) http://www.parallelpython.com/
So is the free lunch really over
There is no such thing as a free lunch. Something which has never
existed can't be over.
or is this just an overhyped
phenomena?
These days, every IT phenomenon is over-hyped.

If you have a CPU-intensive Python program, you may want to consider:
(1) checking that there are not faster/better algorithms for doing
what you want in Python, either built-in or in a 3rd-party library
(2) using psyco
(3) checking your code for sub-optimal constructs

HTH,
John
Sep 6 '08 #4
cnb <ci**********@y ahoo.sewrote:
>
So is the free lunch really over or is this just an overhyped
phenomena?
Remember that your computer is not running one single program. An idle
computer on either Windows or Linux typically has dozens of processes
running. Even if all of those programs are single-threaded, you'll still
be able to keep all of the cores busy.
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Sep 7 '08 #5
On 7 Sep, 00:06, cnb <circularf...@y ahoo.sewrote:
If I buy a multicore computer and I have really intensive program. How
would that be distributed across the cores?
Distribution of processes and threads across processors (cores or
CPUs) is managed by the operating system.

Will algorithms always have to be programmed and told specifically to
run on several cores so if not told it will only utilize one core?
One particular program has to be programmed for concurrency to utilize
multiple cores. But you typically have more than one program running.

So is the free lunch really over or is this just an overhyped
phenomena?
Two slow cores are better than one fast for most purposes. For one
thing, it saves power. It's good for the battries and environment
alike.

Is threading with Python hard?
It's not harder than with other systems. You just subclass
threading.Threa d, which has almost the same interface as Java threads.
Threading with Python is perhaps a bit easier than with other common
platforms, due to the Queue.Queue object and the lack of volatile
objects.

Can you start several processes with Python or just threads?
You can do both. However, remember that Python threads only do what
threads were designed to do back in the 1990s. That is asynchrony for
I/O and UIs, not concurrency on multiple processors for CPU bound
computing. This is due to the "Global Interpreter Lock". The GIL is
better than fine-grained locks for single-threading and concurrency
with multiple processes, but prevent python threads form being used
for concurrency (just as well).

You can do concurrency with Java threads or Win32 threads, but this is
merely a side-effect. You will often see claims form novice
programmers that threads are the only route to concurrency on multi-
core CPUs. In addition to the existence of processes, direct use of
threads from Java, .NET, POSIX, or Win32 APIs is not even the
preferred way of programming for concurrency. Tinkering with low-level
threading APIs for concurrency is error-prone and inefficient. You
will spend a lot of time cleansing your code of dead-locks, live-
locks, volatile objects not being declared volatile, and race
conditions. In addition to that, chances are your code will not
perform or scale very well due to memory contention, cache line
misses, inefficient use of registers due to volatile objects, etc. The
list is endless. That is why Java 6 and .NET 3.5 provide other
abstractions for multi-core concurrency, such as ForkJoin and
Parallel.For. This is also the rationale for using an OpenMP enabled
compiler for C or Fortran, auto-vectorizing C or Fortran compilers,
and novel languages like cilk and erlang.

Traditionally, concurrency om parallel computers have been solved
using tools like BSPlib, MPI, vectorizing Fortran compilers, and even
"ebarassing ly parallel" (running multiple instances of the same
program on different data). OpenMP is a recent addition to the
concurrency toolset for SMP type parallel computers (to which multi-
core x86 processors belong).

If you really need concurrency with Python, look into MPI (PyMPI,
PyPAR, mpi4py), Python/BSP, subprocess module, os.fork (excluding
Windows), pyprocessing package, or Parallel Python. BSP is probably
the least error-prone paradigm for multi-core concurrency, albeit not
the most efficient.

If you decide to move an identified bottleneck from Python to C or
Fortran, you also have the option of using OpenMP or cilk to ease the
work of programming for concurrency. This is my preferred way of
dealing with bad bottlenecks in numerical computing. Remember that you
need not learn the overly complex Python C API. Cython, ctypes, f2py,
or scipy.weave will do just as well. This approach will require you to
manually release the GIL, which can be done in several ways:

- In C extensions between Py_BEGIN_ALLOW_ THREADS and
Py_END_ALLOW_TH READS macros.

- When calling DLL methods using ctypes.cdll or ctypes.windll (not
ctypes.pydll).

- In a "with nogil:" block in a Cython/Pyrex extension.

- With f2py or SWIG, although I have not looked at the details. (I
don't use them.)
Other things to consider:

- Programs that run fast enough run fast enough, even if they only
utilize one core. To qoute C.A.R. Hoare and Donald Knuth, "premature
optimization is the root of all evil in computer programming."

- Psyco, a Python JIT compiler, will often speed up algorithmic code.
Using psyco require to change to your code. Try it and see if your
programs runs fast enough afterwards. YouTube is rumoured to use psyco
to speed ut their Python backend.

- Always use NumPy or SciPy if you do numerical work. They make
numerical code easier to program. The numerical code also runs a lot
faster than a pure python equivalent.

- Sometimes Python is faster than your hand-written C. This is
particularly the case for Python code that make heavy use of built-in
primitives and objects from the standard library. You will spend a lot
of time tuning a linked list or dynamic array to match the performance
of a Python list. Chances are you'll never come up with a sort as fast
as Python's timsort. You'll probably never make your own hash table
that can compete with Pythons dictionaries and sets, etc. Even if you
can, the benefit will be minute and certainly not worth the effort.

- You will get tremendous speedups (often x200 over pure Python) if
you can move a computational bottleneck to C, C++, Fortran, Cython, or
a third-party library (FFTW, LAPACK, Intel MKL, etc.)

- Portions of your Python code that do not constitute important
bottlenecks can just be left in Python. You will not gain anything
substantial from migrating these parts to C, as other parts of your
code dominate. Use a profiler to indentify computational bottlenecks.
It will save you a lot of grief fiddling with premature
optimizations.

That's my fifty cents on Python coding for speed.

Sep 7 '08 #6
On 7 Sep, 06:24, sturlamolden <sturlamol...@y ahoo.nowrote:
- Psyco, a Python JIT compiler, will often speed up algorithmic code.
Using psyco require to change to your code.
Typo. It should say "Using psyco does not require you to change your
code."
Sep 7 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
2174
by: Ioannis Vranos | last post by:
Since multicore processors are about to become mainstream soon, multithreading will become a main concern too. However I am thinking that perhaps for small/medium-sized applications multithreading optimisation should not be a major concern apart from the cases where it makes sense (for example a downloading application where one thread performs the network connection and download and a separate thread updates the data information:...
2
6211
by: Padu | last post by:
Hi, I'm a newbie to C# and I haven't dig into multi-threading in .net (I have some experience with MT in delphi and c++). Let's say I have one of these new pentium D multicore. If I start a program that has 2 threads, will they execute each in a different core? Is there any support in the language to control in which CPU a thread will execute? In a more general sense, how .net uses multi-core/multi-cpu systems? Cheers
6
3648
by: Peter Graf | last post by:
Hi, I want to use to quadcore processor to calculate a matrix with a C++-program. The elapsed time for calculating one entry is very variably (approx. 1-30 min) and I'm not able to estimate the time before the calculation.Therefore simply splitting the matrix in four blocks and calculated each on one core will not use efficiently the processor. Hence my question, is there is a (simple) way to
20
2152
by: gremlin | last post by:
http://www.cilk.com/multicore-blog/bid/6703/C-Inventor-Bjarne-Stroustrup-answers-the-Multicore-Proust-Questionnaire
0
1826
by: gremlin | last post by:
http://www.cilk.com/multicore-blog/bid/6703/C-Inventor-Bjarne-Stroustrup-answers-the-Multicore-Proust-Questionnaire
0
1225
by: Cilk | last post by:
We at Cilk Arts are soon (Jan '09) going to release Cilk++ 1.0, with the goal of delivering the easiest, quickest, and most reliable way to maximize application performance on multicore processors. We have an Early Visibility Program for folks interested in kicking the tires on the alpha/beta versions of the product and multicore-enabling their C++ apps. www.cilk.com Cilk++ 1.0 is best suited for applications that meet the following...
0
8332
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8746
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8627
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7356
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2750
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.