I am a bit confused about what memory looks like in a dual CPU machine from the perspective of a C/C++ program running on Linux.

从Linux上运行的C / C ++程序的角度来看,我对双CPU机器中的内存看起来有点困惑。

Case 1 (understood)

案例1(理解)

With one quad-core HT CPU, 32GB RAM, I can, in theory, write a single process application, using up to 8 threads and up to 32GB RAM without going into swap or overloading the threading facilities - I am ignore the OS and other processes here for simplicity.

使用一个四核HT CPU,32GB RAM,理论上我可以编写单个进程应用程序,使用多达8个线程和高达32GB RAM而无需交换或重载线程设施 - 我忽略了操作系统和其他这里的过程简单。

Case 2 (confusion)

案例2(混乱)

What happens with a dual quad-core HT CPU with 64GB RAM set up?

设置64GB RAM的双四核HT CPU会发生什么?

Development-wise, do you need to write an application to run as two processes (8 threads, 32GB each) that communicate or can you write it as one process (16 threads, 64GB full memory)?

开发方面,你是否需要编写一个应用程序来运行两个进程(8个线程,每个32GB)进行通信,或者你可以将它作为一个进程(16个线程,64GB全内存)编写?

If the answer is the former, what are some efficient modern strategies to utilize the entire hardware? shm? IPC? Also, how do you direct Linux to use a different CPU for each process?

如果答案是前者,那么利用整个硬件的一些有效的现代策略是什么? SHM? IPC?另外,如何指导Linux为每个进程使用不同的CPU?

2 个解决方案

#1


7

From the application's viewpoint, the number of physical CPUs (dies) doesn't matter. Only the number of virtual processors. These include all cores on all processors, and double, if hyperthreading is enabled on a core. Threads are scheduled on them in the same way. It doesn't matter if the cores are all on one die or spread across multiple dies.

从应用程序的角度来看,物理CPU(管芯)的数量无关紧要。只有虚拟处理器的数量。这些包括所有处理器上的所有内核,如果在内核上启用超线程,则为double。线程以相同的方式安排在它们上面。如果核心都在一个芯片上或分布在多个芯片上并不重要。

In general, the best way to handle these things is to not. Don't worry about what's running on which core. Just spawn an appropriate number of threads for your application, (up to a theoretical maximum equal to the total number of cores in the system), and let the OS deal with the scheduling.

一般来说,处理这些事情的最佳方法是不这样做。不要担心在哪个核心上运行什么。只为您的应用程序生成适当数量的线程(最多理论最大值等于系统中的核心总数),并让操作系统处理调度。

The memory is shared amongst all cores in the system, of course. But again, it's up the OS to handle allocation of physical memory. Very few applications really need to worry about how much memory they use, and divvying up that memory between threads. Let the OS handle that.

当然,内存在系统中的所有内核之间共享。但同样,操作系统可以处理物理内存的分配。很少有应用程序真的需要担心它们使用多少内存,并在线程之间分配内存。让操作系统处理。

更多相关文章

  1. Linux 多线程 ”一写多读” 模式下的无锁设计
  2. 如何测试已部署的Web应用程序
  3. window下使用vnc远程登录linux图形界面和运行应用程序 和odroid
  4. Python爬取京东评论(多线程+队列+bs4+pymysql)
  5. 利用读写锁实现sqlite多线程写的问题
  6. [求助][CAB][安装包][CF2.0][SQL][setup]1000分请教:如何将CF2.0
  7. 线程往数据库里插数据时偶尔会报错
  8. SQLite3使用总结备忘(多线程/WAL/锁等)
  9. Android之用Handler实现主线程和子线程互相通信以及子线程和子线

随机推荐

  1. 分支和循环结构的继续熟练
  2. 图解源码 | 接管SpringMVC的自动配置
  3. 肥朝匿名粉丝面经,复习资料自取!
  4. 两道JVM面试题,竟让我回忆起了中学时代!
  5. 无异常日志,就不能排查问题了???
  6. 计算时间差,你的方式或许不是最佳实践!
  7. 用最低的成本,提高你的代码稳壮性。
  8. 阿里规范不建议多表join,可这SQL要怎么写
  9. 为Android系统编译tun.ko模块
  10. Linux网络管理