<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <pre class="moz-signature" cols="72">1. I don't think that this is correct construct too. Since we don't support such kind of construct for locals, we should not support it for globals, 
since OpenMP does not have any difference between locals and globals. I think it is just the problem of the standard that it is not quite clear about it.
Probably, we can support this construct, but not sure that it is required. I don't want to spend my time implementing the things that won't be used and 
not allowed by the standard.
2. I'll check it. All the problems with it because runtime is not quite correct and does not fully support task reductions. Because of that I had to introduce
all that stuff with the threadprivates.
</pre>
    <pre class="moz-signature" cols="72">-------------
Best regards,
Alexey Bataev</pre>
    <div class="moz-cite-prefix">09.03.2018 3:57, Raúl Peñacoba пишет:<br>
    </div>
    <blockquote type="cite"
      cite="mid:0eb58d4c-1946-44a5-8c98-2ed0f1251a0a@bsc.es">I see. In
      that case, what about using task reductions with a global variable
      like the attached example?
      <br>
      <br>
      I've seen that you fixed the storage calls. I've tested it but
      still doesn't work omp_orig initialization. If I'm not wrong, the
      reduction init function use the pointer returned by
      __kmpc_threadprivate_cached() directly without dereference.
      <br>
      <br>
      Regards,
      <br>
      Raúl
      <br>
      El 08/03/18 a las 20:10, Alexey Bataev escribió:
      <br>
      <blockquote type="cite">Your code is not correct. Standard does
        not say, that the reduced items must share the same memory, it
        says that it must use the same variables. In your example the
        variables are different, though they share the same memory.
        <br>
        <br>
        -------------
        <br>
        Best regards,
        <br>
        Alexey Bataev
        <br>
        <br>
        08.03.2018 14:03, Raúl Peñacoba пишет:
        <br>
        <blockquote type="cite">Hi,
          <br>
          <br>
          I mean that it seems that this implementation restricts the
          tasks that
          <br>
          participate in the reduction to be defined in the same lexical
          scope.
          <br>
          I have not been able to find this restriction in the OpenMP
          <br>
          specification. What the spec says about this topic is:
          <br>
          <br>
          "A list item that appears in an in_reduction clause of a
          <br>
          task-generating construct must appear
          <br>
          in a task_reduction clause of a construct corresponding to a
          taskgroup
          <br>
          region that includes
          <br>
          the participating task in its taskgroup set. The construct
          <br>
          corresponding to the innermost region
          <br>
          that meets this condition must specify the same
          reduction-identifier
          <br>
          as the in_reduction
          <br>
          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>
          El 08/03/18 a las 15:30, Alexey Bataev escribió:
          <br>
          <blockquote type="cite">Hi,
            <br>
            <br>
            <blockquote type="cite">
              <blockquote type="cite">
                <blockquote type="cite">Anyway, this implementation of
                  task reductions is not fully
                  <br>
                </blockquote>
              </blockquote>
            </blockquote>
            functional, as only are allowed if the task is created in
            the scope
            <br>
            of taskgroup.
            <br>
            <br>
            What do you mean?Could you provide some more detais?
            <br>
            <br>
            <br>
            -------------
            <br>
            Best regards,
            <br>
            Alexey Bataev
            <br>
            08.03.2018 7:47, Raúl Peñacoba пишет:
            <br>
            <blockquote type="cite">Hi,
              <br>
              <br>
              I did some little research and I have realized that the
              patch I
              <br>
              attached doesn't fix the problem completely. I fixed the
              storage of
              <br>
              the data. When a using task reduction with vla, or a class
              that uses
              <br>
              omp_orig to initialize the private copies, the size of the
              vla and
              <br>
              omp_orig are stored in a storage using
              __kmpc_threadprivate_cached().
              <br>
              <br>
              The problem comes because, since in outline parallel
              function each
              <br>
              reduction has lazy_priv flag, the initialization will be
              done in
              <br>
              __kmpc_task_reduction_get_th_data(), called from outline
              task
              <br>
              function. This is done _before_storing the vla size or
              omp_orig, so
              <br>
              the initialization would be wrong in these cases.
              <br>
              <br>
              I think that if the storage is put before the
              <br>
              __kmpc_task_reduction_get_th_data() it should work.
              <br>
              <br>
              Anyway, this implementation of task reductions is not
              fully
              <br>
              functional, as only are allowed if the task is created in
              the scope
              <br>
              of taskgroup.
              <br>
              <br>
              Sorry for the mail duplicate.
              <br>
              <br>
              Regards,
              <br>
              <br>
              Raúl
              <br>
              <br>
              El 06/03/18 a las 16:21, Alexey Bataev escribió:
              <br>
              <blockquote type="cite">Hi, thanks for the report, I'll
                take a look.
                <br>
                <br>
                -------------
                <br>
                Best regards,
                <br>
                Alexey Bataev
                <br>
                06.03.2018 4:25, Raúl Peñacoba via cfe-dev пишет:
                <br>
                <blockquote type="cite">Hi,
                  <br>
                  <br>
                  I've noticed that clang does not work properly when
                  using task
                  <br>
                  reductions with non-constant arrays and/or classes
                  with omp_orig
                  <br>
                  constructor initializers.
                  <br>
                  <br>
                  As reduction initialize/combine/finalize functions
                  only receive
                  <br>
                  references to whatever should be initialized,
                  combined..., clang
                  <br>
                  generates some additional storages to save the size of
                  the
                  <br>
                  reduction array and a pointer to the omp_orig. That
                  storages are
                  <br>
                  generated through __kmpc_thread_private_cached() calls
                  in both
                  <br>
                  reduction functions and outline task function.
                  <br>
                  <br>
                  The problem is that the storage used in outline task
                  function does
                  <br>
                  not match the storage in reduction functions. This
                  happens in
                  <br>
                  programs that have a task reduction or a taskloop
                  reduction with
                  <br>
                  the in_reduction clause.
                  <br>
                  <br>
                  To solve this i made an ugly patch that reuses the
                  SourceLocation
                  <br>
                  of CodeGenFunction::EmitOMPTaskgroupDirective() in
                  <br>
                  CodeGenFunction::EmitOMPTaskBasedDirective() to match
                  the storages
                  <br>
                  and make it work. Anyway, i suppose that there is a
                  better way to
                  <br>
                  fix this.
                  <br>
                  <br>
                  Index: CGStmtOpenMP.cpp
                  <br>
===================================================================
                  <br>
                  --- CGStmtOpenMP.cpp    (revision 326685)
                  <br>
                  +++ CGStmtOpenMP.cpp    (working copy)
                  <br>
                  @@ -2713,6 +2713,8 @@
                  <br>
                                                    
                  emitEmptyBoundParameters);
                  <br>
                    }
                  <br>
                  <br>
                  +static SourceLocation reductionLoc;
                  <br>
                  +
                  <br>
                    void CodeGenFunction::EmitOMPTaskBasedDirective(
                  <br>
                        const OMPExecutableDirective &S, const
                  OpenMPDirectiveKind
                  <br>
                  CapturedRegion,
                  <br>
                        const RegionCodeGenTy &BodyGen, const
                  TaskGenTy &TaskGen,
                  <br>
                  @@ -2952,7 +2954,7 @@
                  <br>
                            // FIXME: This must removed once the runtime
                  library is
                  <br>
                  fixed.
                  <br>
                            // Emit required threadprivate variables for
                  <br>
                            // initilizer/combiner/finalizer.
                  <br>
                  -       
                  CGF.CGM.getOpenMPRuntime().emitTaskReductionFixups(CGF,
                  <br>
                  S.getLocStart(),
                  <br>
                  +       
                  CGF.CGM.getOpenMPRuntime().emitTaskReductionFixups(CGF,
                  <br>
                  reductionLoc,
                  <br>
                  RedCG, Cnt);
                  <br>
                          }
                  <br>
                        }
                  <br>
                  @@ -3180,8 +3182,9 @@
                  <br>
                              std::advance(IRHS, 1);
                  <br>
                            }
                  <br>
                          }
                  <br>
                  +      reductionLoc = S.getLocStart();
                  <br>
                          llvm::Value *ReductionDesc =
                  <br>
                  -         
                  CGF.CGM.getOpenMPRuntime().emitTaskReductionInit(CGF,
                  <br>
                  S.getLocStart(),
                  <br>
                  +         
                  CGF.CGM.getOpenMPRuntime().emitTaskReductionInit(CGF,
                  <br>
                  reductionLoc,
                  <br>
                  LHSs, RHSs, Data);
                  <br>
                          const auto *VD =
                  <br>
cast<VarDecl>(cast<DeclRefExpr>(E)->getDecl());
                  <br>
                          CGF.EmitVarDecl(*VD);
                  <br>
                  <br>
                  Regards,
                  <br>
                  <br>
                  Raúl
                  <br>
                  <br>
                  <br>
<a class="moz-txt-link-freetext" href="https://nam02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fbsc.es%2Fdisclaimer&data=02%7C01%7C%7Cbdc4c4de2d04480706e308d5859bcff2%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636561826607210068&sdata=8EdV%2BOxP0hlHRaTsWdbDjPGQZsjKrQVwB4UBpIDscsU%3D&reserved=0">https://nam02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fbsc.es%2Fdisclaimer&data=02%7C01%7C%7Cbdc4c4de2d04480706e308d5859bcff2%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636561826607210068&sdata=8EdV%2BOxP0hlHRaTsWdbDjPGQZsjKrQVwB4UBpIDscsU%3D&reserved=0</a>
                  <br>
                  <br>
                </blockquote>
              </blockquote>
              <br>
              <br>
              WARNING / LEGAL TEXT: This message is intended only for
              the use of
              <br>
              the individual or entity to which it is addressed and may
              contain
              <br>
              information which is privileged, confidential,
              proprietary, or
              <br>
              exempt from disclosure under applicable law. If you are
              not the
              <br>
              intended recipient or the person responsible for
              delivering the
              <br>
              message to the intended recipient, you are strictly
              prohibited from
              <br>
              disclosing, distributing, copying, or in any way using
              this message.
              <br>
              If you have received this communication in error, please
              notify the
              <br>
              sender and destroy and delete any copies you may have
              received.
              <br>
              <br>
<a class="moz-txt-link-freetext" href="https://nam02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.bsc.es%2Fdisclaimer&data=02%7C01%7C%7Cbdc4c4de2d04480706e308d5859bcff2%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636561826607210068&sdata=VijKwX7k2dgfvTE7yBrXjch1lF7lYB2RNMKCW273btM%3D&reserved=0">https://nam02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.bsc.es%2Fdisclaimer&data=02%7C01%7C%7Cbdc4c4de2d04480706e308d5859bcff2%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636561826607210068&sdata=VijKwX7k2dgfvTE7yBrXjch1lF7lYB2RNMKCW273btM%3D&reserved=0</a>
              <br>
<a class="moz-txt-link-rfc2396E" 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"><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></a>
              <br>
              <br>
            </blockquote>
          </blockquote>
          <br>
          <br>
          WARNING / LEGAL TEXT: This message is intended only for the
          use of the
          <br>
          individual or entity to which it is addressed and may contain
          <br>
          information which is privileged, confidential, proprietary, or
          exempt
          <br>
          from disclosure under applicable law. If you are not the
          intended
          <br>
          recipient or the person responsible for delivering the message
          to the
          <br>
          intended recipient, you are strictly prohibited from
          disclosing,
          <br>
          distributing, copying, or in any way using this message. If
          you have
          <br>
          received this communication in error, please notify the sender
          and
          <br>
          destroy and delete any copies you may have received.
          <br>
          <br>
<a class="moz-txt-link-freetext" href="https://nam02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.bsc.es%2Fdisclaimer&data=02%7C01%7C%7Cbdc4c4de2d04480706e308d5859bcff2%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636561826607210068&sdata=VijKwX7k2dgfvTE7yBrXjch1lF7lYB2RNMKCW273btM%3D&reserved=0">https://nam02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.bsc.es%2Fdisclaimer&data=02%7C01%7C%7Cbdc4c4de2d04480706e308d5859bcff2%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636561826607210068&sdata=VijKwX7k2dgfvTE7yBrXjch1lF7lYB2RNMKCW273btM%3D&reserved=0</a>
          <br>
<a class="moz-txt-link-rfc2396E" href="https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.bsc.es%2Fdisclaimer&data=02%7C01%7C%7Ca45b287f1ee24a78c93808d585273f8e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636561325966851856&sdata=IYNPTvByADBir%2F950dCUevcJHWEIOo90Xx5raSJ2rS8%3D&reserved=0"><https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.bsc.es%2Fdisclaimer&data=02%7C01%7C%7Ca45b287f1ee24a78c93808d585273f8e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636561325966851856&sdata=IYNPTvByADBir%2F950dCUevcJHWEIOo90Xx5raSJ2rS8%3D&reserved=0></a>
          <br>
          <br>
        </blockquote>
        <br>
      </blockquote>
      <br>
      <br>
      <br>
<a class="moz-txt-link-freetext" href="https://nam02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fbsc.es%2Fdisclaimer&data=02%7C01%7C%7Cbdc4c4de2d04480706e308d5859bcff2%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636561826607210068&sdata=8EdV%2BOxP0hlHRaTsWdbDjPGQZsjKrQVwB4UBpIDscsU%3D&reserved=0">https://nam02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fbsc.es%2Fdisclaimer&data=02%7C01%7C%7Cbdc4c4de2d04480706e308d5859bcff2%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636561826607210068&sdata=8EdV%2BOxP0hlHRaTsWdbDjPGQZsjKrQVwB4UBpIDscsU%3D&reserved=0</a><br>
    </blockquote>
    <br>
  </body>
</html>