jmartin wrote:
> I have made a multithread version of a program (load a file into
> database), and with two processors I get the double of time in the
> multithread than in the process (unithread) version.
>
> I have done the test of creating a unique thread that does the same
> code that the process version of the program and it takes more time
> that the process without creating the thread. [... etc]
Optimizing algorithms on multithreaded systems can be hard. If you
split an operation on an array, for example, then you will need each
processor to have half of the memory from that array, which means that
inevitably which may have started as a single continguous array has to
be at least half copied into the cache of the other processor. This is
ok if your algorithm is very expensive in comparison to the cost of
copying the array, for example. But its something trivial like just
summing up the elements of the array, I could see how it could easily
be slower, or at least no faster, on a single threaded machine.
Optimization on multithreading system, still relies good algorithm
design and the use of tools such as profilers to isolate performance
bugs. In that sense, its the same as single threading. But you have
to be aware of hidden performance problems such as increased memory
locality issues such as I have described above.
--
Paul Hsieh
http://www.pobox.com/~qed/
http://bstring.sf.net/