<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-forward-container">Here is a recent discussion that
      is appropriate for the CppAD mailing list:<br>
      <br>
      Hi Brad,
      <div class=""><br class="">
      </div>
      <div class="">Thanks for the further clarification. I think I
        understand the memory model a little better now.  For case 2,
        I’ll just protect Independent with a “critical" block. </div>
      <div class=""><br class="">
      </div>
      <div class="">Feel free to forward this to the mailing list.</div>
      <div class=""><br class="">
      </div>
      <div class="">AJ</div>
      <div class=""><br class="">
      </div>
      <div>
        <blockquote type="cite" class="">
          <div class="">On Aug 30, 2015, at 5:19 PM, Brad Bell &lt;<a
              moz-do-not-send="true" class="moz-txt-link-abbreviated"
              href="mailto:bradbell@uw.edu"><a class="moz-txt-link-abbreviated" href="mailto:bradbell@uw.edu">bradbell@uw.edu</a></a>&gt;
            wrote:</div>
          <br class="">
          <div class="">
            <div text="#000000" bgcolor="#FFFFFF" class="">
              <div class="moz-cite-prefix">On 08/30/2015 06:50 AM, AJ
                Bostian wrote:<br class="">
              </div>
              <blockquote
                cite="mid:17C68768-3CA1-4799-8178-41E1C611AF9D@bostian.us.com"
                type="cite" class="">
                <div class="">Hi Brad,</div>
                <div class=""><br class="">
                </div>
                <div class="">Thanks for the clarification.</div>
                <div class=""><br class="">
                </div>
                <div class="">In my first use case, OpenMP will
                  different spawn threads for different iterations of
                  the loop, so it seems that there will be no issue with
                  calling Independent/Dependent inside that loop.  Is
                  that the right interpretation?  In that case, does the
                  parallel memory initialization need to occur
                  per-thread, or once for the whole program?  (Or does
                  it even need to be explicitly initialized in that
                  manner?)</div>
              </blockquote>
              The initialization needs to be done in single thread mode;
              see<br class="">
                  <a moz-do-not-send="true"
                class="moz-txt-link-freetext"
                href="http://www.coin-or.org/CppAD/Doc/ta_parallel_setup.xml">http://www.coin-or.org/CppAD/Doc/ta_parallel_setup.xml</a>
              <blockquote
                cite="mid:17C68768-3CA1-4799-8178-41E1C611AF9D@bostian.us.com"
                type="cite" class="">
                <div class=""><br class="">
                </div>
                <div class="">In my second use case, I guess I just need
                  to make sure that the threads synchronize before
                  Independent/Dependent are called, and also make sure
                  that the root thread does the calling.</div>
              </blockquote>
              A different recording is going for each thread, so the
              calls to Independent must be done by the thread that will
              do the corresponding computation. You must make sure that
              the thread numbers are the same for the computations you
              want in the same recording. It might be simpler to start
              with the team of OpenMP threads example and see if you can
              make it do what you want.<br class="">
              <blockquote
                cite="mid:17C68768-3CA1-4799-8178-41E1C611AF9D@bostian.us.com"
                type="cite" class="">
                <div class=""><br class="">
                </div>
                <div class="">AJ</div>
                <div class=""><br class="">
                </div>
                <div class="">
                  <blockquote type="cite" class="">
                    <div class="">On Aug 30, 2015, at 4:39 PM, Brad Bell
                      &lt;<a moz-do-not-send="true"
                        class="moz-txt-link-abbreviated"
                        href="mailto:bradbell@uw.edu">bradbell@uw.edu</a>&gt;

                      wrote:</div>
                    <br class="Apple-interchange-newline">
                    <div class="">
                      <div text="#000000" bgcolor="#FFFFFF" class="">
                        The restriction on parallel CppAD is that there
                        can only be one currently active call to
                        Independent per thread. An attempt to have
                        multiple calls active at the same time will
                        generate an error message.  I will try to make
                        this more explicit under the Parallel heading
                        for Independent; see<br class="">
                            <a moz-do-not-send="true"
                          class="moz-txt-link-freetext"
                          href="http://www.coin-or.org/CppAD/Doc/independent.xml#Parallel%20Mode">http://www.coin-or.org/CppAD/Doc/independent.xml#Parallel%20Mode</a><br
                          class="">
                        <br class="">
                        For examples, see<br class="">
                            <a moz-do-not-send="true"
                          class="moz-txt-link-freetext"
                          href="file:///home/bradbell/cppad.git/doc/multi_thread.htm">file:///home/bradbell/cppad.git/doc/multi_thread.htm</a><br
                          class="">
                            <a moz-do-not-send="true"
                          class="moz-txt-link-freetext"
                          href="file:///home/bradbell/cppad.git/doc/thread_test.cpp.htm">file:///home/bradbell/cppad.git/doc/thread_test.cpp.htm</a><br
                          class="">
                        and the OpenMP specific case<br class="">
                            <a moz-do-not-send="true"
                          class="moz-txt-link-freetext"
                          href="file:///home/bradbell/cppad.git/doc/team_openmp.cpp.htm">file:///home/bradbell/cppad.git/doc/team_openmp.cpp.htm</a><br
                          class="">
                            <br class="">
                        <br class="">
                        <div class="moz-cite-prefix">On 08/30/2015 04:38
                          AM, AJ Bostian wrote:<br class="">
                        </div>
                        <blockquote
                          cite="mid:DB0F8285-18D3-400E-A212-572D9AE27D83@bostian.us.com"
                          type="cite" class=""> Hi Brad,
                          <div class=""><br class="">
                          </div>
                          <div class="">I’ve been using a number of AD
                            tools for a while now, and I find myself
                            needing one that works well in a parallel
                            environment.  Scanning through github, I see
                            that cppad has parallel support.  However, I
                            have two use cases, and I want to verify
                            that both are feasible.  Could you advise
                            me?</div>
                          <div class=""><br class="">
                          </div>
                          <div class="">Each case involves a for-loop
                            parallelized with OpenMP.</div>
                          <div class=""><br class="">
                          </div>
                          <div class="">Case 1: The calls to
                            Independent, Dependent, and Forward/Reverse
                            are completely self-contained within the
                            loop.  (I.e., each iteration of the loop
                            deals with a completely different
                            mathematical function, and these functions
                            do not need to survive outside the loop.)</div>
                          <div class=""><br class="">
                          </div>
                          <div class="">Case 2: The calls to
                            Independent, Dependent, and Forward/Reverse
                            are completely outside the loop.  (I.e.,
                            each iteration of the loop is helping to
                            build up a larger mathematical function.)</div>
                          <div class=""><br class="">
                          </div>
                          <div class="">Can cppad handle both of these?
                             If so, does memory initialization occur in
                            the same manner in each?</div>
                          <div class=""><br class="">
                          </div>
                          <div class="">Thanks for your help,</div>
                          <div class="">AJ</div>
                          <br class="">
                          <div apple-content-edited="true" class="">
                            <div style="letter-spacing: normal; orphans:
                              auto; text-align: start; text-indent: 0px;
                              text-transform: none; white-space: normal;
                              widows: auto; word-spacing: 0px;
                              -webkit-text-stroke-width: 0px; word-wrap:
                              break-word; -webkit-nbsp-mode: space;
                              -webkit-line-break: after-white-space;"
                              class="">
                              <div style="letter-spacing: normal;
                                orphans: auto; text-align: start;
                                text-indent: 0px; text-transform: none;
                                white-space: normal; widows: auto;
                                word-spacing: 0px;
                                -webkit-text-stroke-width: 0px;
                                word-wrap: break-word;
                                -webkit-nbsp-mode: space;
                                -webkit-line-break: after-white-space;"
                                class="">
                                <div style="letter-spacing: normal;
                                  orphans: auto; text-align: start;
                                  text-indent: 0px; text-transform:
                                  none; white-space: normal; widows:
                                  auto; word-spacing: 0px;
                                  -webkit-text-stroke-width: 0px;
                                  word-wrap: break-word;
                                  -webkit-nbsp-mode: space;
                                  -webkit-line-break:
                                  after-white-space;" class="">
                                  <div style="letter-spacing: normal;
                                    orphans: auto; text-align: start;
                                    text-indent: 0px; text-transform:
                                    none; white-space: normal; widows:
                                    auto; word-spacing: 0px;
                                    -webkit-text-stroke-width: 0px;
                                    word-wrap: break-word;
                                    -webkit-nbsp-mode: space;
                                    -webkit-line-break:
                                    after-white-space;" class="">
                                    <div style="letter-spacing: normal;
                                      orphans: auto; text-align: start;
                                      text-indent: 0px; text-transform:
                                      none; white-space: normal; widows:
                                      auto; word-spacing: 0px;
                                      -webkit-text-stroke-width: 0px;
                                      word-wrap: break-word;
                                      -webkit-nbsp-mode: space;
                                      -webkit-line-break:
                                      after-white-space;" class="">
                                      <div style="letter-spacing:
                                        normal; orphans: auto;
                                        text-align: start; text-indent:
                                        0px; text-transform: none;
                                        white-space: normal; widows:
                                        auto; word-spacing: 0px;
                                        -webkit-text-stroke-width: 0px;
                                        word-wrap: break-word;
                                        -webkit-nbsp-mode: space;
                                        -webkit-line-break:
                                        after-white-space;" class="">
                                        <div class="">—</div>
                                        <div class="">Dr. AJ Bostian</div>
                                        <div class="">University of
                                          Tampere</div>
                                        <div class="">Tel: +358 50 318
                                          7328</div>
                                        <div class="">Email: <a
                                            moz-do-not-send="true"
                                            class="moz-txt-link-abbreviated"
                                            href="mailto:aj@bostian.us"><a class="moz-txt-link-abbreviated" href="mailto:aj@bostian.us">aj@bostian.us</a></a>.com</div>
                                        <div class="">Web: <a
                                            moz-do-not-send="true"
                                            href="http://aj.bostian.us.com/"
                                            class="">aj.bostian.us.com</a></div>
                                        <div class=""><br class="">
                                        </div>
                                      </div>
                                    </div>
                                  </div>
                                </div>
                              </div>
                            </div>
                            <br class="Apple-interchange-newline">
                          </div>
                          <br class="">
                        </blockquote>
                        <br class="">
                      </div>
                    </div>
                  </blockquote>
                </div>
                <br class="">
              </blockquote>
              <br class="">
            </div>
          </div>
        </blockquote>
      </div>
      <br class="">
      <br>
    </div>
    <br>
    <br>
  </body>
</html>