上午遇到的多核问题?

zyx0507 2008-01-14 01:44:48
上午的时候,一同时问了我一个问题:当一个应用程序执行在多核的CPU上时,如果这个应用程序
是多线程,那么这些线程是如果分配在每个核上运行的?欢迎讨论?
...全文
159 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
OpenHero 2008-01-18
  • 打赏
  • 举报
回复
如果你没有指定线程中那个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


等等
不知道说得详细不
lz不清楚的地方,我们可以共同探讨:)
mengmengswat 2008-01-18
  • 打赏
  • 举报
回复
分配线程到处理核心是操作系统的事,应该不能指定,可以说随机分配,然后来同时执行多个线程.

567

社区成员

发帖
与我相关
我的任务
社区描述
英特尔® 边缘计算,聚焦于边缘计算、AI、IoT等领域,为开发者提供丰富的开发资源、创新技术、解决方案与行业活动。
社区管理员
  • 英特尔技术社区
  • shere_lin
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧