OpenMP:如何刷新指针目标? [英] OpenMP: how to flush pointer target?

查看:97
本文介绍了OpenMP:如何刷新指针目标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚注意到以下代码未在OpenMP中编译(在GCC 4.5.1下):

I’ve just noticed that the following code doesn’t compile in OpenMP (under GCC 4.5.1):

struct job {
    unsigned busy_children;
};

job* j = allocateJob(…);
// …

#pragma omp flush(j->busy_children)

编译器抱怨要刷新参数列表中的->,根据OpenMP规范,它是正确的:flush希望将"id表达式"列表作为参数,这基本上仅表示(限定)允许使用ID,不能使用表达式.

The compiler complains about the -> in the argument list to flush, and according to the OpenMP specification it’s right: flush expects as arguments a list of "id-expression"s, which basically means only (qualified) IDs are allowed, no expressions.

此外,该规范还介绍了有关flush和指针的信息:

Furthermore, the spec says this about flush and pointers:

如果列表中存在指针,则将刷新指针本身,而不是刷新指针所指向的内存块.

If a pointer is present in the list, the pointer itself is flushed, not the memory block to which the pointer refers.

当然.但是,由于OpenMP也不允许我取消引用指针,因此我基本上无法刷新指针(指针目标).

Of course. However, since OpenMP also doesn’t allow me to dereference the pointers I basically cannot flush a pointee (pointer target).

–那么引用呢?规范没有提到它们,但我不确定以下内容是否符合要求,并且实际上会刷新该指针对象.

– So what about references? The spec doesn’t mention them but I’m not confident that the following is conformant, and will actually flush the pointee.

unsigned& busy_children = j->busy_children;
#pragma omp flush(busy_children)

这可以保证正常工作吗?

如果没有,如何冲洗指尖?

推荐答案

flush指令已使OpenMP ARB长期困扰.如此之多,以至于有人谈论将其完全删除-尽管这会带来其他问题.使用flush(list)很难获得正确的答案,即使OpenMP专家也很难获得正确的答案.它的问题在于,它的定义方式可以由编译器在代码中移动.这意味着您应该远离使用flush(list).

The flush directive has given the OpenMP ARB a headache for a long time. So much so, that there has been talk about removing it completely - though that creates other problems. Using flush(list), is extremely difficult to get correct and even the OpenMP experts have a great deal of trouble getting it correct. The problem with it, is that the way it is defined it can be moved around in your code by the compiler. That means that you should stay away from using flush(list).

关于您是否能够刷新pointe的问题,只有一种方法可以做到,那就是使用flush(无列表).这将刷新整个线程环境,因此编译器无法移动它.似乎手忙脚乱",但实际上,编译器在不使用列表的情况下刷新时使用刷新是相当不错的.

As for your question about being able to flush a pointee, there is only one way to do that and that is to use flush (without a list). This will flush your entire thread environment and as such, can not be moved by the compiler. It seems "heavy handed", but the compilers are actually pretty good about flushing what is necessary when using flush without a list.

这篇关于OpenMP:如何刷新指针目标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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