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

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

相关问答

更多
  • 我做了一些研究,这是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
  • 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_balanc ...
  • 好。 我的主要问题的答案是NO,你不能像这样创建一个PreparedStatement: PreparedStatement stmt = con.prepareSelect("sql statement1; sql statement2;"); 暂时运行单个语句来暂时改变会话对于一点SQL是行得通的,但是同意似乎很糟糕,并且也令人无法接受地减缓了响应。 选项似乎是补丁或升级,或查看no_use_hash提示(我认为这也会很慢)。 将看代码。 OK. The answer to my primary qu ...
  • 开始一个类似于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) inst ...
  • 经过一些激烈的分析后,我发现我遇到了一个oracle bug - > Bug 18461054:TRUNC WITH DATE BIND分区表给出了错误的结果 所以这个问题可能会发生截断或圆形日期。 当前会话的解决方法是 alter session set "_optimizer_generate_transitive_pred"=false; 还有补丁补丁18461054:TRUNC与分区表上的日期结合给出了错误的结果 希望能帮助别人而不是我:) 最好, 帕特里克 After some intense ...
  • 我看不到你的SQL有任何明显的“错误”。 但是,如果学生12345以任何方式丢失来自(dcis,studentsdcid,guardianid,externalident,student_number)的数据,或者任何表中没有匹配的数据。 然后,由于您正在使用内部联接,因此不会返回任何记录。 2意见建议: *尝试搜索学生12345时尝试将内部联接更改为左联接。如果它返回任何数据,您将看到可能缺少的内容 *尝试从第一个sql语句中搜索出现在列表中的学生。 如果这仍然没有返回任何记录,那么您可能必须重构您的sq ...
  • 你究竟想在这里实现什么目标? 当表A和B行之间存在连接时,您希望将一些数据插入到表A ,但是不要使用B列的列中的任何值。 合并将不会像你编写它一样工作,因为你必须在WHEN MATCHED THEN子句中有一个UPDATE或DELETE语句,你不能在那里有一个INSERT 。 另一方面,在WHEN NOT MATCHED THEN clasue中,你只能有INSERT 。 有关MERGE更多信息,请访问: Oracle文档 - MERGE语句 如果你从=更改为!= ,它将无法工作,因为那时你将在MERGE的 ...
  • 一种更清洁的方法是使用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 PARAMETERS ( ...
  • ROWNUM是结果集的伪属性,而不是基表的属性。 ROWNUM是在选择行之后定义的,但是在它们按ORDER BY子句排序之前定义。 编辑:我之前写的ROWNUM错了,所以这里有新的信息: 您可以在WHERE子句中以有限的方式使用ROWNUM,以测试它是否仅小于正整数。 有关更多详细信息,请参见ROWNUM伪列 。 SELECT ... WHERE ROWNUM < 10 目前尚不清楚ROWNUM在JOIN子句的上下文中具有什么值,因此结果可能未定义。 似乎有一些特殊情况下使用ROWNUM处理表达式,例如W ...
  • 这不是Oracle错误。 首先,您不应该在FROM子句中使用逗号。 您应该始终使用显式JOIN语法。 但这不是你的具体问题。 可变分辨率和范围是。 如果在查询中有诸如interface_name的引用,则Oracle首先查找具有该名称的列。 它永远不会看到变量。 将变量命名为区别对象,因此最终得到的代码更像是: . . . FROM payments.multi_value_lookup_config mvlc JOIN payments.message_source ms ...

相关文章

更多

最新问答

更多
  • 如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
  • linux的常用命令干什么用的
  • 由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
  • 如何交换返回集中的行?(How to swap rows in a return set?)
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • 使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
  • Java中的不可变类(Immutable class in Java)
  • WordPress发布查询(WordPress post query)
  • 如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
  • 是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
  • GEP分段错误LLVM C ++ API(GEP segmentation fault LLVM C++ API)
  • 绑定属性设置器未被调用(Bound Property Setter not getting Called)
  • linux ubuntu14.04版没有那个文件或目录
  • 如何使用JSF EL表达式在param中迭代变量(How to iterate over variable in param using JSF EL expression)
  • 是否有可能在WPF中的一个单独的进程中隔离一些控件?(Is it possible to isolate some controls in a separate process in WPF?)
  • 使用Python 2.7的MSI安装的默认安装目录是什么?(What is the default installation directory with an MSI install of Python 2.7?)
  • 寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
  • ckeditor config.protectedSource不适用于editor.insertHtml上的html元素属性(ckeditor config.protectedSource dont work for html element attributes on editor.insertHtml)
  • linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
  • Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
  • 将CouchDB与AJAX一起使用是否安全?(Is it safe to use CouchDB with AJAX?)
  • 懒惰地初始化AutoMapper(Lazily initializing AutoMapper)
  • 使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)
  • Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)
  • 无法在新线程中从FREContext调用getActivity()?(Can't call getActivity() from FREContext in a new thread?)
  • 在Alpine上升级到postgres96(/ usr / bin / pg_dump:没有这样的文件或目录)(Upgrade to postgres96 on Alpine (/usr/bin/pg_dump: No such file or directory))
  • 如何按部门显示报告(How to display a report by Department wise)
  • Facebook墙贴在需要访问令牌密钥后无法正常工作(Facebook wall post not working after access token key required)
  • Javascript - 如何在不擦除输入的情况下更改标签的innerText(Javascript - how to change innerText of label while not wiping out the input)
  • WooCommerce / WordPress - 不显示具有特定标题的产品(WooCommerce/WordPress - Products with specific titles are not displayed)