Thread: Multiple processors

  1. #1
    Registered User Dohojar's Avatar
    Join Date
    Feb 2002
    Posts
    115

    Question Multiple processors

    I was wonder if anyone knows anything about programming duel processors. Basically what I want to do is run multiple threads in the same program but I want to use more than one processor. The machine this will be for has two 2 gig processors and I want to split the threads between them so that while one processor is working on one thread, the other processor can be doing its own thing at the same time. If anyone can offer me some advice or show me a website that has something about this it would be a great help
    Dohojar Moajbuj
    Time is the greatest teacher, too bad it kills all its students

  2. #2
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    The only way you will be able to do this is using an OS dependent thread library that was designed to take advantage of dual processors. Look into the Win32 API documentation on the msdn site if your using windows, look into pthreads if your on unix or linux. As for mac im not sure since ive never owned one, well not since '82.
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  3. #3
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Generally, the OS handles the dispatching of threads to processors in a multi CPU system. So if you write a multithreaded application, and more than one of those threads is in a computable state, (i.e. not blocked), and a processor is available, the OS will schedule one of your threads onto it, repeating until all processors are busy.

    There are a few more esoteric OS's around where you have more control over the dispatching. These tend to be found on machines with many processors, or specialised vector processors, (Cray for example). Even then, the special vectorising compilers tend to do the basic work giving you the opportunity to tweak it if you feel the need.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  4. #4
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    This is OS specific. You need a distributed OS for this which supports this kind of programming. What OS are you using?

  5. #5
    Registered User Dohojar's Avatar
    Join Date
    Feb 2002
    Posts
    115
    right now I am using windows xp for this but it will have to run on unix as well. My computer only has one processor but the machine the code will be for has 2 processors and the company I am working for wants to ensure both processors are used.

    "So if you write a multithreaded application, and more than one of those threads is in a computable state, (i.e. not blocked), and a processor is available, the OS will schedule one of your threads onto it, repeating until all processors are busy. "
    So the O/S will split the threads between the 2 processors? I have already got the code to run multi-threaded app but I was hoping I could specify which processor used which thread but if I can't so be it.

    And by "not blocked" .. do you mean kinda like a mutex block? not too sure how I would impliment more than one mutex.. right now the code is written using only one mutex to block threads once a given thread has control of a function.

    thanks for the help guys
    Dohojar Moajbuj
    Time is the greatest teacher, too bad it kills all its students

  6. #6
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    >So the O/S will split the threads between the 2 processors? I
    >have already got the code to run multi-threaded app but I was
    >hoping I could specify which processor used which thread but if
    >I can't so be it.

    The OS decides which part of the code is performed by which processor. In a higher programming model the programmer doesn't care or even know about how the OS does this, just like RPC. At a lower level it is possible, but then you need to know the internal mechanisms of your OS.

    For more information on operating systems I recommend the next book. It is also about distributed operating systems.

    Modern Operating Systems
    Andrew S. Tanenbaum
    ISBN: 0-13-031358-0

    For more info on a distributed operating system and an implementation, you could take a look at:

    http://www.cs.vu.nl/pub/amoeba/

  7. #7
    Registered User Dohojar's Avatar
    Join Date
    Feb 2002
    Posts
    115
    Thanks for the help all. I think I will have to do some experimenting
    Dohojar Moajbuj
    Time is the greatest teacher, too bad it kills all its students

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 06-08-2009, 03:03 PM
  2. Print a File on Multiple Processors
    By Cell in forum Linux Programming
    Replies: 6
    Last Post: 03-25-2009, 09:39 AM
  3. Linker errors - Multiple Source files
    By nkhambal in forum C Programming
    Replies: 3
    Last Post: 04-24-2005, 02:41 AM
  4. Replies: 1
    Last Post: 05-01-2003, 02:52 PM
  5. using multiple processors
    By eats only heads in forum Tech Board
    Replies: 14
    Last Post: 10-31-2002, 04:54 PM