如何在内存中(C编程)分配内存在一个特定的地方吗? [英] How to allocate memory in a specific place in memory (C programming)?

查看:163
本文介绍了如何在内存中(C编程)分配内存在一个特定的地方吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个CPU,每个6核的服务器。 CPU的每一个连接到4 GB的RAM。我有一个运行在同一code(轻微改变)在并行两个CPU,每个内核使用4个线程并行程序。

I have a server with 2 CPUs, each with 6 cores. Each of the CPUs are connected to 4 GB of RAM. I have a parallel program that runs the same code (with minor changes) in both CPUs in parallel, using 4 threads in each core.

为了提高效率,这将是最好的,如果有一种方法,以确保CPU的运行1的code只能在其相应的RAM,而不是CPU 2,反之亦然的RAM分配内存,如CPU之间的通信将创建一个开销。

For efficiency reasons, it would be best if there was a way to ensure that the code running on CPU 1 would only allocate memory on its corresponding ram and not on the ram of CPU 2, and vice versa, as the communication between CPUs would create an overhead.

有没有办法做到这一点?

Is there any way to do this?

推荐答案

假设你使用的是Linux,默认NUMA策略prefers在本地分配内存,所以你所要求的应工作外的开箱。这可以通过配置来改变虽然。

Assuming you are using Linux, the default NUMA policy prefers to allocate memory locally, so what you are asking for should work out-of-the-box. This can be changed through configuration though.

无论当前的政策,您可以使用 libnuma 来分配本地NUMA节点上的内存(这就是呼叫RAM +插座/核心组合)或特定节点, numa_alloc_local numa_alloc_onnode ,等等。释放内存使用 numa_free 。请参见 NUMA(7)的手册页和的 numa_alloc(3)有关这些功能的详细信息和一般的NUMA系统。

Whatever the current policy you can use libnuma to allocate memory on the local NUMA node (that's what the call the combination of RAM + socket / core) or on a specific node, with numa_alloc_local, numa_alloc_onnode, and so on. To free the memory use numa_free. See the man pages of numa(7) and numa_alloc(3) for details on these functions and the NUMA system in general.

这篇关于如何在内存中(C编程)分配内存在一个特定的地方吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆