<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <p><tt>Hi,</tt></p>
    <p><tt>I mean that </tt><tt>it seems that this implementation
        restricts the tasks that participate in the reduction to be
        defined in the same lexical scope. I have not been able to find
        this restriction in the OpenMP specification. What the spec says
        about this topic is:</tt></p>
    <tt>"A list item that appears in an in_reduction clause of a
      task-generating construct must appear</tt><tt><br>
    </tt><tt> in a task_reduction clause of a construct corresponding to
      a taskgroup region that includes</tt><tt><br>
    </tt><tt> the participating task in its taskgroup set. The construct
      corresponding to the innermost region</tt><tt><br>
    </tt><tt> that meets this condition must specify the same
      reduction-identifier as the in_reduction</tt><tt><br>
    </tt><tt> clause."<br>
      <br>
      I tried to compile the attached file. The compile command is:<br>
      <br>
      clang -fopenmp task_red.cc<br>
      <br>
      Regards,<br>
      Raúl<br>
      <br>
    </tt>
    <div class="moz-cite-prefix">El 08/03/18 a las 15:30, Alexey Bataev
      escribió:<br>
    </div>
    <blockquote type="cite"
cite="mid:AM5PR0902MB1923C2CE4109CA0A68FF9BF185DF0@AM5PR0902MB1923.eurprd09.prod.outlook.com">
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <p>Hi,</p>
      <p>>>> <tt>Anyway, this implementation of task
          reductions is not fully functional, as only are allowed if the
          task is created in the scope of taskgroup.</tt><tt><br>
        </tt></p>
      <p><tt>What do you mean?Could you provide some more detais?<br>
        </tt></p>
      <p><tt><br>
        </tt></p>
      <pre class="moz-signature" cols="72">-------------
Best regards,
Alexey Bataev</pre>
      <div class="moz-cite-prefix">08.03.2018 7:47, Raúl Peñacoba пишет:<br>
      </div>
      <blockquote type="cite"
        cite="mid:6d491557-35fb-9d45-62be-d1b33dadb424@bsc.es">
        <meta http-equiv="Content-Type" content="text/html;
          charset=utf-8">
        <p><tt>Hi,</tt></p>
        <tt> </tt>
        <p><tt>I did some little research and I have realized that the
            patch I attached doesn't fix the problem completely. I fixed
            the storage of the data. When a using task reduction with
            vla, or a class that uses omp_orig to initialize the private
            copies, the size of the vla and omp_orig are stored in a
            storage using __kmpc_threadprivate_cached().</tt></p>
        <tt> </tt>
        <p><tt>The problem comes because, since in outline parallel
            function each reduction has lazy_priv flag, the
            initialization will be done in
            __kmpc_task_reduction_get_th_data(), called from outline
            task function. This is done </tt><tt><u>before</u></tt><tt>
            storing the vla size or omp_orig, so the initialization
            would be wrong in these cases.</tt></p>
        <tt> </tt>
        <p><tt>I think that if the storage is put before the
            __kmpc_task_reduction_get_th_data() it should work.</tt></p>
        <tt> </tt>
        <p><tt>Anyway, this implementation of task reductions is not
            fully functional, as only are allowed if the task is created
            in the scope of taskgroup.</tt><tt><br>
          </tt></p>
        <p><tt>Sorry for the mail duplicate.<br>
          </tt> </p>
        <tt> </tt>
        <p><tt>Regards,</tt></p>
        <tt> Raúl</tt><tt><br>
        </tt><tt><br>
        </tt>
        <div class="moz-cite-prefix"><tt>El 06/03/18 a las 16:21, Alexey
            Bataev escribió:</tt><tt><br>
          </tt></div>
        <blockquote type="cite"
cite="mid:AM5PR0902MB192332923553F3139032AB6385D90@AM5PR0902MB1923.eurprd09.prod.outlook.com">
          <p><tt>Hi, thanks for the report, I'll take a look.</tt><tt><br>
            </tt> </p>
          <pre class="moz-signature" cols="72">-------------
Best regards,
Alexey Bataev</pre>
          <div class="moz-cite-prefix"><tt>06.03.2018 4:25, Raúl
              Peñacoba via cfe-dev пишет:</tt><tt><br>
            </tt> </div>
          <blockquote type="cite"
            cite="mid:%3C8c87489c-07b9-25bc-0b3b-66d9d295bf8f@bsc.es%3E"><tt>Hi,
            </tt><tt><br>
            </tt> <tt><br>
            </tt><tt> I've noticed that clang does not work properly
              when using task reductions with non-constant arrays and/or
              classes with omp_orig constructor initializers. </tt><tt><br>
            </tt> <tt><br>
            </tt><tt> As reduction initialize/combine/finalize functions
              only receive references to whatever should be initialized,
              combined..., clang generates some additional storages to
              save the size of the reduction array and a pointer to the
              omp_orig. That storages are generated through
              __kmpc_thread_private_cached() calls in both reduction
              functions and outline task function. </tt><tt><br>
            </tt> <tt><br>
            </tt><tt> The problem is that the storage used in outline
              task function does not match the storage in reduction
              functions. This happens in programs that have a task
              reduction or a taskloop reduction with the in_reduction
              clause. </tt><tt><br>
            </tt> <tt><br>
            </tt><tt> To solve this i made an ugly patch that reuses the
              SourceLocation of
              CodeGenFunction::EmitOMPTaskgroupDirective() in
              CodeGenFunction::EmitOMPTaskBasedDirective() to match the
              storages and make it work. Anyway, i suppose that there is
              a better way to fix this. </tt><tt><br>
            </tt> <tt><br>
            </tt><tt> Index: CGStmtOpenMP.cpp </tt><tt><br>
            </tt><tt>
=================================================================== </tt><tt><br>
            </tt><tt> --- CGStmtOpenMP.cpp    (revision 326685) </tt><tt><br>
            </tt><tt> +++ CGStmtOpenMP.cpp    (working copy) </tt><tt><br>
            </tt><tt> @@ -2713,6 +2713,8 @@ </tt><tt><br>
            </tt><tt>                                  
              emitEmptyBoundParameters); </tt><tt><br>
            </tt><tt>  } </tt><tt><br>
            </tt> <tt><br>
            </tt><tt> +static SourceLocation reductionLoc; </tt><tt><br>
            </tt><tt> + </tt><tt><br>
            </tt><tt>  void CodeGenFunction::EmitOMPTaskBasedDirective(
            </tt><tt><br>
            </tt><tt>      const OMPExecutableDirective &S, const
              OpenMPDirectiveKind CapturedRegion, </tt><tt><br>
            </tt><tt>      const RegionCodeGenTy &BodyGen, const
              TaskGenTy &TaskGen, </tt><tt><br>
            </tt><tt> @@ -2952,7 +2954,7 @@ </tt><tt><br>
            </tt><tt>          // FIXME: This must removed once the
              runtime library is fixed. </tt><tt><br>
            </tt><tt>          // Emit required threadprivate variables
              for </tt><tt><br>
            </tt><tt>          // initilizer/combiner/finalizer. </tt><tt><br>
            </tt><tt> -       
              CGF.CGM.getOpenMPRuntime().emitTaskReductionFixups(CGF,
              S.getLocStart(), </tt><tt><br>
            </tt><tt> +       
              CGF.CGM.getOpenMPRuntime().emitTaskReductionFixups(CGF,
              reductionLoc, </tt><tt><br>
            </tt><tt> RedCG, Cnt); </tt><tt><br>
            </tt><tt>        } </tt><tt><br>
            </tt><tt>      } </tt><tt><br>
            </tt><tt> @@ -3180,8 +3182,9 @@ </tt><tt><br>
            </tt><tt>            std::advance(IRHS, 1); </tt><tt><br>
            </tt><tt>          } </tt><tt><br>
            </tt><tt>        } </tt><tt><br>
            </tt><tt> +      reductionLoc = S.getLocStart(); </tt><tt><br>
            </tt><tt>        llvm::Value *ReductionDesc = </tt><tt><br>
            </tt><tt> -         
              CGF.CGM.getOpenMPRuntime().emitTaskReductionInit(CGF,
              S.getLocStart(), </tt><tt><br>
            </tt><tt> +         
              CGF.CGM.getOpenMPRuntime().emitTaskReductionInit(CGF,
              reductionLoc, </tt><tt><br>
            </tt><tt> LHSs, RHSs, Data); </tt><tt><br>
            </tt><tt>        const auto *VD =
              cast<VarDecl>(cast<DeclRefExpr>(E)->getDecl());
            </tt><tt><br>
            </tt><tt>        CGF.EmitVarDecl(*VD); </tt><tt><br>
            </tt> <tt><br>
            </tt><tt> Regards, </tt><tt><br>
            </tt> <tt><br>
            </tt><tt> Raúl </tt><tt><br>
            </tt> <tt><br>
            </tt> <tt><br>
            </tt> <tt><a class="moz-txt-link-freetext"
href="https://nam03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fbsc.es%2Fdisclaimer&data=02%7C01%7C%7C2a787fae16d1409fb12808d584f2b8da%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636561100369995188&sdata=dRdsyHQ2zmAHZbnAdxiGhTMO%2ByEbHnhIo5nKgWIu9fA%3D&reserved=0"
                originalsrc="http://bsc.es/disclaimer"
shash="j7hdeiLsvAbUdw0iIrDJrZvuOyMdvlonX8weB4d1Q1uT9nkNF8ym02ddIvdyzK7FAOuXCFVJzjRkaiJ9zH1CBUZFsKgf5NG0Siz9LQbDKueL1BcoJZMWVHW9SJnq5L7rUdtGZTpVxjReN/KriqmiXm1t3L6Qps7ptWLQOE7RHVM="
                moz-do-not-send="true">http://bsc.es/disclaimer</a></tt><tt>
            </tt><tt><br>
            </tt> <tt><br>
            </tt> </blockquote>
          <tt><br>
          </tt> </blockquote>
        <tt><br>
        </tt> <br>
        <br>
        WARNING / LEGAL TEXT: This message is intended only for the use
        of the individual or entity to which it is addressed and may
        contain information which is privileged, confidential,
        proprietary, or exempt from disclosure under applicable law. If
        you are not the intended recipient or the person responsible for
        delivering the message to the intended recipient, you are
        strictly prohibited from disclosing, distributing, copying, or
        in any way using this message. If you have received this
        communication in error, please notify the sender and destroy and
        delete any copies you may have received. <br>
        <br>
        <a
href="https://nam03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.bsc.es%2Fdisclaimer&data=02%7C01%7C%7C2a787fae16d1409fb12808d584f2b8da%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636561100369995188&sdata=Qg460eDN4kZxnL4NIiP06MjaE85rnbyx2M%2FyVR7jif8%3D&reserved=0"
          originalsrc="http://www.bsc.es/disclaimer"
shash="Hb30Ww/zrerjodaCGq1SFTIRJezQFUmTWNWr/UFbLxxJfNfu6z1IztPoXzhGacw7SmfcPYX+a6fFrIKMiVKNxv7ZLVJKNr9xrc+OgJ6FFQA6iDsDFMVSka/MMXYNW3NcFARpWH9FKzAeMmnb7mlJJQXMD/PXdSJztISceF1zH0c="
          moz-do-not-send="true">http://www.bsc.es/disclaimer</a> <br>
      </blockquote>
      <br>
    </blockquote>
    <br>
  
<br>
<br>
WARNING / LEGAL TEXT: This message is intended only for the use of the
individual or entity to which it is addressed and may contain
information which is privileged, confidential, proprietary, or exempt
from disclosure under applicable law. If you are not the intended
recipient or the person responsible for delivering the message to the
intended recipient, you are strictly prohibited from disclosing,
distributing, copying, or in any way using this message. If you have
received this communication in error, please notify the sender and
destroy and delete any copies you may have received.
<br><br>
<a href="http://www.bsc.es/disclaimer">http://www.bsc.es/disclaimer</a>
<br>
</body>
</html>