OpenMP - Serialize for-loop在并行区域中包含并行for循环(OpenMP - Serialise for-loop in Parallel Region which Contains Parallel for-loop)

我问这个问题一个非常相似的问题,但那里只有一个答案,但对我来说并没有用。

我在main()有一个并行区域,它带有一个调用函数new_value()的for循环:

int main(int argc, char** argv)
{
    omp_set_num_threads(4);

#pragma omp parallel default(shared) private(...)
{
    for(int i = 0; i < MAX_VALUE; i++)
        new_value(...);
}

    return 0;
}

new_value()看起来像:

void new_value(...)
{
#pragma omp for schedule(static, chunk_width)
    for(int i = 0; i < N; i++)
        arr[i] = update();
}

我遇到的问题是我不希望main()的for循环被并行化(即总共运行MAX_VALUE * 4次)。

我基本上希望这个循环能够连续运行,但new_value()的for循环要使用四个线程运行。

我在循环之前尝试了#pragma omp single ,但它导致程序死锁或挂起某些东西。 我也尝试了由已经链接的线程提示的嵌套并行方法,但是我得到了相同的结果。

任何解决方案将不胜感激。


I'm asking a very similar question to this chap but there is only one answer there and it hasn't proved useful for me.

I have a parallel region in main() with a for-loop which calls the function new_value():

int main(int argc, char** argv)
{
    omp_set_num_threads(4);

#pragma omp parallel default(shared) private(...)
{
    for(int i = 0; i < MAX_VALUE; i++)
        new_value(...);
}

    return 0;
}

And new_value() looks like:

void new_value(...)
{
#pragma omp for schedule(static, chunk_width)
    for(int i = 0; i < N; i++)
        arr[i] = update();
}

The issue I am having is that I do not want the for-loop in main() to be parallelised (i.e. ran MAX_VALUE * 4 times in total).

I essentially want that one loop to be ran serially but the for-loop in new_value() to be ran with four threads.

I tried #pragma omp single before the loop but it caused the program to deadlock or hang on something. I also tried the nested parallelism approach as suggest by the already linked thread but I got the same result.

Any solutions would be appreciated.


原文:https://stackoverflow.com/questions/47475715
2021-11-05 18:11

满意答案

这不是Oracle错误。 首先,您不应该在FROM子句中使用逗号。 您应该始终使用显式JOIN语法。

但这不是你的具体问题。 可变分辨率和范围是。

如果在查询中有诸如interface_name的引用,则Oracle首先查找具有该名称的列。 它永远不会看到变量。 将变量命名为区别对象,因此最终得到的代码更像是:

   . . .
   FROM payments.multi_value_lookup_config mvlc JOIN
        payments.message_source ms
        ON  ms.pk_message_source = mvlc.fk_pk_message_source 
   WHERE  ms.interface_name = v_interface_name
          ms.message_format_name = v_message_format_name /*'MT202'*/
          mvlc.mapping_column_name  = v_source_field
          mvlc.lookup_category_type = v_determined_field_type

This is not an Oracle bug. First, you should never use commas in the FROM clause. You should always use explicit JOIN syntax.

But that is not your specific problem. Variable resolution and scoping is.

When you have a reference such as interface_name in a query, then Oracle looks first for columns with that name. It never sees the variables. Name the variables something distinguishing, so you end up with code that is more like this:

   . . .
   FROM payments.multi_value_lookup_config mvlc JOIN
        payments.message_source ms
        ON  ms.pk_message_source = mvlc.fk_pk_message_source 
   WHERE  ms.interface_name = v_interface_name
          ms.message_format_name = v_message_format_name /*'MT202'*/
          mvlc.mapping_column_name  = v_source_field
          mvlc.lookup_category_type = v_determined_field_type

相关问答

更多

具有内部联接的ORACLE Listagg(ORACLE Listagg with an Inner Join)

我做了一些研究,这是SQL Fiddle的答案! http://sqlfiddle.com/#!4/783b8/1/0 I did some research, and here is the answer on SQL Fiddle! http://sqlfiddle.com/#!4/783b8/1/0

Oracle右外连接(Oracle right outer join)

FROM accounts a, payments p WHERE (a.account_balance <= a.low_balance_level OR a.account_balance <= 0) AND a.account_id = p.account_id(+) AND p.payment_status_code(+) = 'R' ^^^ FROM accounts a, payments p WHERE (a.account_b...

PreparedStatement和Oracle 10g错误(PreparedStatement and Oracle 10g bug)

好。 我的主要问题的答案是NO,你不能像这样创建一个PreparedStatement: PreparedStatement stmt = con.prepareSelect("sql statement1; sql statement2;"); 暂时运行单个语句来暂时改变会话对于一点SQL是行得通的,但是同意似乎很糟糕,并且也令人无法接受地减缓了响应。 选项似乎是补丁或升级,或查看no_use_hash提示(我认为这也会很慢)。 将看代码。 OK. The answer to my prima...

如何在Oracle中的一个条件HAVING和AND中组合(How to combine in one condition HAVING and AND in Oracle)

开始一个类似于where的子句(除了在聚合之后应用(例如sums)而不是之前),所以你只能在查询中使用它一次: having ((sum(col)<=30 and type=4) or (sum(col)>=30 and type=5)) 您还需要group by子句,指定查询分组的列: group by type, ... Having begins a clause similar to where (except applied after aggregation (e.g. sums)...

Oracle 12c:错误的截断(日期)导致错误的数据(Oracle 12c: Bug with trunc(date) results in wrong data)

经过一些激烈的分析后,我发现我遇到了一个oracle bug - > Bug 18461054:TRUNC WITH DATE BIND分区表给出了错误的结果 所以这个问题可能会发生截断或圆形日期。 当前会话的解决方法是 alter session set "_optimizer_generate_transitive_pred"=false; 还有补丁补丁18461054:TRUNC与分区表上的日期结合给出了错误的结果 希望能帮助别人而不是我:) 最好, 帕特里克 After some int...

使用INNER JOIN添加另一个WHERE条件时,Oracle SELECT失败(Oracle SELECT fails when adding another WHERE condition with INNER JOINs)

我看不到你的SQL有任何明显的“错误”。 但是,如果学生12345以任何方式丢失来自(dcis,studentsdcid,guardianid,externalident,student_number)的数据,或者任何表中没有匹配的数据。 然后,由于您正在使用内部联接,因此不会返回任何记录。 2意见建议: *尝试搜索学生12345时尝试将内部联接更改为左联接。如果它返回任何数据,您将看到可能缺少的内容 *尝试从第一个sql语句中搜索出现在列表中的学生。 如果这仍然没有返回任何记录,那么您可能必须重...

基于内部联接oracle sql插入(Insert based on inner join oracle sql)

你究竟想在这里实现什么目标? 当表A和B行之间存在连接时,您希望将一些数据插入到表A ,但是不要使用B列的列中的任何值。 合并将不会像你编写它一样工作,因为你必须在WHEN MATCHED THEN子句中有一个UPDATE或DELETE语句,你不能在那里有一个INSERT 。 另一方面,在WHEN NOT MATCHED THEN clasue中,你只能有INSERT 。 有关MERGE更多信息,请访问: Oracle文档 - MERGE语句 如果你从=更改为!= ,它将无法工作,因为那时你将在M...

Oracle:文件和表之间的内部联接(Oracle:inner join between file and table)

一种更清洁的方法是使用EXTERNAL TABLE 。 使用这样的create语句来创建TYPES_external表。 CREATE TABLE TYPES_external ( id NUMBER(5), name VARCHAR2(50), Values VARCHAR2(50) ) ORGANIZATION EXTERNAL ( TYPE ORACLE_LOADER DEFAULT DIRECTORY USER_DIR ACCESS PARAMET...

Rownum处于连接状态(Rownum in the join condition)

ROWNUM是结果集的伪属性,而不是基表的属性。 ROWNUM是在选择行之后定义的,但是在它们按ORDER BY子句排序之前定义。 编辑:我之前写的ROWNUM错了,所以这里有新的信息: 您可以在WHERE子句中以有限的方式使用ROWNUM,以测试它是否仅小于正整数。 有关更多详细信息,请参见ROWNUM伪列 。 SELECT ... WHERE ROWNUM < 10 目前尚不清楚ROWNUM在JOIN子句的上下文中具有什么值,因此结果可能未定义。 似乎有一些特殊情况下使用ROWNUM处理表达...

内部联接条件被忽略 - 看起来像Oracle错误(Inner join condition is disregarded - looks like an Oracle bug)

这不是Oracle错误。 首先,您不应该在FROM子句中使用逗号。 您应该始终使用显式JOIN语法。 但这不是你的具体问题。 可变分辨率和范围是。 如果在查询中有诸如interface_name的引用,则Oracle首先查找具有该名称的列。 它永远不会看到变量。 将变量命名为区别对象,因此最终得到的代码更像是: . . . FROM payments.multi_value_lookup_config mvlc JOIN payments.message_source ...

相关文章

更多

Hadoop lzo文件的并行map处理

Hadoop集群中启用了lzo后,还需要一些配置,才能使集群能够对单个的lzo文件进行并行的map操作 ...

Linux内核Bridge代码的STP的实现(转)

http://damocles.blogbus.com/logs/13476603.html 网络拓扑 ...

Hadoop 通过distcp进行并行复制

通过distcp进行并行复制 前面的HDFS访问模型都集中于单线程的访问。例如通过指定文件通配,我们 ...

Hadoop集群lzo文件的并行map处理

Hadoop集群中启用了lzo后,还需要一些配置,才能使集群能够对单个的lzo文件进行并行的map操作 ...

用 Hadoop 进行分布式并行编程, 第 1 部分基本概念与安装部署

简介: Hadoop 是一个实现了 MapReduce 计算模型的开源分布式并行编程框架,借助于 Ha ...

Hadoop是什么 分享 PPT

云计算概念 Google的云计算 Hadoop HDFS Map/Reduce 日志框架的Hadoop ...

用 Hadoop 进行分布式并行编程, 第 2 部分程序实例与分析

简介: Hadoop 是一个实现了 MapReduce 计算模型的开源分布式并行编程框架,借助于 Ha ...

Hadoop真实分布式并行环境部署经验

一、安装环境 (1)Master机器:用VMServer虚拟的RedHat Linux AS4 Upd ...

物理专业英语词汇(H-N)

物理专业英语词汇(H-N) H h maser 氢微波激射器氢脉泽 h parameter h参数 ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本