bluecode wrote:
The race conditions and buffer overflows never seem to end.
It does seem that many real problems never get fixed, while new toolkits multiply like rabbits.
Quote:
I believe in giving the application designer as much control as possible over managing resources because that enables the best possible design
for that specific application.
After that it becomes the OS' job to make sure the applications live together harmoniously which is something most OS don't seem particularly good at.
I think that was what I was trying to say
Quote:
A good simple example is an email client. Most people have multiple email accounts but most (all?) email clients fetch mail serially and most of them lock the UI while the mail is being fetched. This is obviously the easy, "safe" way to write an email client because serialization is hard. But there's no reason there couldn't be a UI thread so the UI stays unlocked and you could compose and search and read mail while you're fetching from *all* the mail servers in parallel. It's just that nobody did this (AFAIK).
Ah. But this is exactly what OS/2 did. The IBM recommended practices for OS/2 programs were "For any non-trivial application (i.e., takes more than 1/10th second to complete - this was on a 386, btw) then immediately spin off three threads." One is to listen for user input, one to do the work, and I forget what the third was. At the time I used MR/2 ICE for mail - it was very uncommon to have more than one mailbox so I never tried fetching mail from several places at once, but MR/2 did spin off worker threads to fetch mail while you could browse through your mail directories, read messages in another window, write mail in another window, etc - all while other threads fetched mail in the background AND the user interface never went dead while any single task waited for completion.
This was the whole design philosophy of OS/2, in a time when Unix didn't even have posix threads.
It worked, too. It was nice. (The braindead SIQ was not so nice though - although, in a way, the crappy siq
forced
people to write programs correctly.)
Quote:
No OS is intelligent enough to split up this work into meaningful logical components.
Agreed, it isn't ... but the os schedular is smart enough to assign resources to all the different programs which want them. So if one program needs ten threads and three processes while another needs one process with nine threads and five other processes need to run in the background, then let the scheduler do that. Don't let Joe Sixpack decide that since the computer has four cores, wull by gawd I'm gonna make my application use four cores !
Not smart
Quote:
The external parallelizing layers and tools aren't a real solution. They're just a po-man's way of getting an extra bump for not much effort. People have to buy more and more hardware to keep up with lamer and lamer software.
I didn't mean to promote that crap. Let me hop down to making friends and influencing people below and you can see what I meant ...
jwp wrote:
Your comments seem to make the presumption that one program only needs one process.
No, my quote does not make that presumption
at all
. In fact, your statement scares me. Do you know how a computer works ?
Quote:
knowing about the resources available is important for multiprocessing.
For general computing and desktop use,
no it is not
Quote:
Otherwise, how many processes should the task be divided into? There are basically a few choices: (1) do one thing at a time, (2) use some magic number conjured out of thin air, or (3) make a very large number of processes (potentially wasting a lot of time and memory).
Jesus. The task should be divided up
according to what needs to get done.
Using Bluecode's example of an email client :
Open the app with one thread, immediately spin off another thread to actually draw the windows, another to do the work to fill them. Thread One is listener thread for user input. User decides to collect mail, clicks
[email protected]
and one new thread created to collect those emails. User has two more accounts, clicks
[email protected]
and tommy@the_grill.org . One worker thread each. Three sets of mails being collected (seemingly) simultaneously, user interface still responsive. Mr User can even browse the main window and open last week's mail (another thread) or if he likes, open another window and write a happy birthday letter to his Mom (another thread.)
These threads and/or processes are all dependent
on what he needs to do
, not some peculiar calculation based on how many cores are available.
Now, what happens in the larger picture ? Due to the fact that an operating system has a scheduler, with a single core computer the scheduler will decide when each of these threads is handled. The scheduler will also be handling a lot of other tasks, because nowadays even a laptop is doing a lot of things "at once" (not really at once but it seems that way.)
The beauty of doing this correctly is that you can now take this exact same program and put it on a 4-core computer. Now, if the application has sixteen threads, instead of them lining up in a row like a freight train, the scheduler can hand out a task to every cores
as the cores become available.
You can't just decide that since you have four cores you're going to have four threads. First off, there's other stuff going on in the computer. Second, that's no more effective than having four DOS computers under one piece of sheet metal. Multi-tasking isn't about having an army of little computers that don't talk to each other. It's about doing a number of things in a way which seems simultaneous (although it really isn't.)
Quote:
There are many very useful programs that do need to know how to divide up work in order for them to fork the correct number of processes.
Sure. But there is no need for them to have any idea whatsoever about how many processors the computer has. If the app needs ten threads, give it ten threads. Then let the scheduler decide how to hand out cpu time.
Here's how it works in real life - let's say you have four cores available. There are 76 tasks running (I just ran top, that's what's going right now on my O350.) Your app opens, it adds another x # of tasks, let's say three threads to open. Are you going to choose 4 threads just because the box has four cores ? What's the point of that ? It's already processing another 76 tasks, how does 4 fit in there ? (Don't say 19 times.) You think it's going to preempt everything else just because your app wants four threads
NOW
, like a spolied child ?
Bullshit. There's no reason whatseover to know how many cores the box has. Divide the app up into what it needs, then let Mr Scheduler hand out cpu-time as a core becomes available.
Quote:
For example, pbzip2 (parallel bzip2) and pigz (parallel gzip) can run an order of magnitude faster than just using bzip2 and gzip, respectively. Likewise, GNU Make can take advantage of parallelism when building a project. The same goes for GNU Parallel -- that program splits up work into subprocesses and does tasks in parallel.
Just had this discussion with smj a little ... knowing the number of cores available is once again
not
the way to decide how to program this. For example, you have a 512 p O3900 and a 256k zip file. What are you going to do, check the number of cores and split it into 512 tasks ? That's stupid.
That's an extreme example but the point is valid. There are other factors that decide the proper nuber of threads. For general use, the number of cores available is
not
a factor.
Quote:
There are also special libraries that are used specifically for parallelism, and they also need to be able to detect the number of processors.
There is probably a good use for those libraries but general desktop computing is
not
one of them. An application should be correctly written for the job is has to do, not shoehorned into some one-size-fits-all shortcut that doesn't work worth a shit.
Quote:
I was reading through the code for GNU Parallel, and the code for detecting the number of processors was lacking, to say the least. If I remember correctly, it basically just works for Linux, FreeBSD, Solaris, AIX, and Darwin. Libraries and utilities specifically meant to execute tasks in parallel (and therefore remove the low-level detection from the application itself), should have better processor detection code that works for IRIX, HP-UX, NetBSD, OpenBSD, etc.
My instinctive feeling is to say, "GNU Parallel sounds like worthless shit."
Quote:
I want to create a small reference implementation so developers who need to write software like this can refer to the script.
I'd be the last one to criticize someone for writing software that includes Irix
However, I disagree with the idea that you can just stuff these things into some kind of script-kiddy package. If we take Fireflop as an example, I have read that it's actually heavily multi-threaded. But the thing is, it doesn't fucking work. What it
should
be doing does not even resemble what it
does
do. That piece of crap should be ajoy on a 4p box, but instead it's a nightmare. Multi-processing has to fit what the job is, not some easy-peasy 'pour in single-thread code at one end and get ha-chachachacha multi-thread code out the other end' fantasy.
You know, IBM is not a bunch of dummies. Really. The longer you hang out in computerland, the more you have to respect them.