如果我使用OpenMP刷新功能,我的操作系统如何知道刷新的方向?(How does my OS know in which direction to flush if I use OpenMP flu

系统教程 行业动态 更新时间:2024-06-14 17:04:02
如果我使用OpenMP刷新功能,我的操作系统如何知道刷新的方向?(How does my OS know in which direction to flush if I use OpenMP flush function?)

读取共享变量的线程首先调用flush ,写入共享变量的线程之后必须调用OpenMP flush ,以保持共享变量在主内存中并缓存同步。 flush功能如何知道冲洗的方向? 它需要知道哪个变量(主存储器或缓存)更新。 我假设,但我不确定,操作系统或CPU以某种方式处理这个问题。 有人知道吗?

A thread that reads a shared variable has first to call flush, and a thread that writes to a shared variable has to call OpenMP flush afterwards, to keep the shared variable in main memory and cache synchronized. How does the flush function know in which direction to flush? It needs to know which of both variables (main memory or cache) is newer. I assume, but I am not sure, that the OS or CPU take care of this somehow. Does someone know?

最满意答案

flush不是一个函数 - 它是一个OpenMP 编译器指令 。 它会影响编译器生成可执行代码的方式,并指示它在flush-set中同步所有优化变量(存储在CPU寄存器或其他显式可编程缓存/线程本地内存中)的值。 这类似于volatile存储修饰符对代码生成的影响,但具有更有限的点局部效应。

它是如何工作的? 在解析源代码时,编译器会分析语句流和受这些语句影响的数据(变量)。 因此,编译器根据代码构建执行图和数据依赖图。 它确切地知道每个变量的值的使用位置和方式以及执行哪个代码块会影响哪些变量。 然后,编译器尝试通过简化图形来优化代码,并通过使用CPU寄存器来存储中间值或通过使用另一个来获得更快的线程可寻址本地存储器来减少昂贵的存储器操作的数量。 flush指令在执行图中添加了特殊点,其中编译器必须显式地将线程的内存视图(寄存器变量和本地内存变量)与全局共享内存同步。 由于编译器首先构建了依赖图,因此它确切地知道刷新集中的哪些变量被修改,因此必须写入共享内存; 必须从共享内存中读取flush-set中的所有其他变量。

所以你的问题的答案是,通常是编译器处理flush指令而不是OS,尽管编译器可能会调用OS来实际实现flush,例如在具有显式可编程高速缓存/本地存储器的系统上。 但是还应该注意OpenMP是一个抽象标准 ,它可以在许多不同的硬件平台上实现,并且其中一些平台提供某些硬件可以帮助更有效地实现OpenMP抽象(例如IBM的Blue Gene /中的CPU ASIC) Q提供了许多这样的功能)。

flush is not a function - it is an OpenMP compiler directive. It affects the way the compiler generates the executable code and instructs it to synchronise the values of all optimised variables (stored in CPU registers or other explicitly programmable cache / thread-local memory) in the flush-set. This is similar to the effect that the volatile storage modifier has on code generation, but has more limited point-local effect.

How does it work? While parsing the source code, the compiler analyses the flow of statements and the data (variables) that gets affected by those statements. Consequently the compiler builds an execution graph and a data dependency graph from the code. It knows exactly where and how the value of each variable is being used and the execution of which code block affects which variables. Then the compiler tries to optimise the code by simplifying the graph and to reduce the number of expensive memory operations by either using CPU registers to store intermediate values or by using another for of faster thread-addressable local memory. The flush directive adds special points in the execution graph, where the compiler must explicitly synchronise the memory view of the thread (register variables and local-memory variables) with the global shared memory. Since the compiler has built the dependency graph in the first place, it knows exactly which variables in the flush-set were modified and hence have to be written to the shared memory; all other variables in the flush-set have to be read from the shared memory.

So the answer to your question is that it is usually the compiler who processes the flush directive, not the OS, although the compiler might call into the OS to actually implement the flush, e.g. on systems with explicitly programmable caches/local memories. But one should also note that OpenMP is an abstract standard, which can be implemented on many different hardware platforms and that some of those platforms provide certain hardware that can help with implementing the OpenMP abstractions more efficiently (e.g. the CPU ASIC in IBM's Blue Gene/Q provides many such features).

更多推荐

本文发布于:2023-04-24 20:57:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/8efe59dc0af7f282ac1cfcb234e2413e.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:操作系统   方向   功能   OpenMP   function

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!