如果你没有指定线程中那个core上运行,那么cpu会自动调度你的线程,按照OS自己定义的一套线程调度规则来调度你的线程。
但是如果你指定了线程执行的亲和性,那就可以指定在那个core运行你的线程,在windows中,有这样的api函数给你用,在linux中也更方便的api指定,不过这个都比较麻烦,需要自己来写调度算法,但是线程不一定就能很好的配合,而发挥优势。
也有很多线程库来帮你解决:
例如有一些线程库
Thread Programming
Linux Tutorial: POSIX Threads
http://yolinux.com/TUTORIALS/LinuxTutorialPosixThreads.html
Multithreaded Programming (pthreads Tutorial)
http://vergil.chemistry.gatech.edu/resources/programming/threads.html
GNU Pth - The GNU Portable Threads
http://www.gnu.org/software/pth/
POSIX Threads Programming
http://www.llnl.gov/computing/tutorials/pthreads/
Intel Threading Building Block
http://osstbb.intel.com/
SWIG POSIX threads
http://math.arizona.edu/~swig/documentation/pthreads/
还有用openmp的规范来解决的
OpenMP Programming
OpenMP.org
http://www.openmp.org/drupal/
Introducing OpenMP: A Portable, Parallel Programming API for Shared Memory Multiprocessors
http://developers.sun.com/sunstudio/articles/omp-intro.html
Sun OpemMP API User's Guide
http://docs.sun.com/doc/819-3694
OpenMP in Visual C++
http://msdn2.microsoft.com/en-us/library/tt15eb9t(VS.80).aspx
OpenMP Tutorial
http://www.mhpcc.edu/training/workshop2/openMP/MAIN.html
如果是多进程,或者是多机协同:
还可以用mpi
MPI Programming
MPI Forum
http://www.mpi-forum.org/
MPI-the complete reference: Volume 1
http://www.netlib.org/utk/papers/mpi-book/node1.html
MPICH2
http://www-unix.mcs.anl.gov/mpi/mpich/
MPI Forum
http://www.mpi-forum.org/
A User's Guide to MPI
ftp://math.usfca.edu/pub/MPI/mpi.guide.ps.Z
Parallel Programming with MPI
http://www.cs.usfca.edu/mpi/
MPI Tutorial
http://www.mhpcc.edu/training/workshop/mpi/MAIN.html
Tutorial on MPI
http://www-unix.mcs.anl.gov/mpi/tutorial/gropp/talk.html
MPI-IO Tutorial
http://www.mhpcc.edu/training/workshop2/mpi_io/MAIN.html
Introduction to MPI-IO
http://www.nersc.gov/nusers/resources/software/libs/io/mpiio.html