<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic firstprivate is hungry in Intel® Moderncode for Parallel Architectures</title>
    <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/firstprivate-is-hungry/m-p/860067#M2263</link>
    <description>Hi, &lt;BR /&gt;i am learning openmp and i want to parallelize one part of my simulation routine with linked list structure. Following some examples from the net, i modified my code, but it does not work according my expectations. The parallel part of the code is draining my memory. I need to iterate several times through the complete linked list. Every time when the "firstprivate" makes a private copy of the Item from the linked list, it is taking some part of the memory, but after the job is done and one "task" is closed, the memory is not released. Is it normal or am i doing something wrong? How can i solve this? &lt;BR /&gt;&lt;BR /&gt;thank you for your tips. test example:  (compiled with:  icc -g -O0 -openmp -o test ./test.cc )&lt;BR /&gt;&lt;BR /&gt;critical part of test routine:&lt;BR /&gt;
&lt;PRE&gt;[cpp]for(i=1;i&amp;lt;=1000;i++)  // MORE interations needs MORE memory&lt;BR /&gt;{&lt;BR /&gt;   pP = pFirst;&lt;BR /&gt;   #pragma omp parallel num_threads(2)&lt;BR /&gt;   {&lt;BR /&gt;      #pragma omp single nowait&lt;BR /&gt;      {&lt;BR /&gt;         while (pP != NULL)&lt;BR /&gt;         {&lt;BR /&gt;            #pragma omp task private(l) firstprivate(pP)&lt;BR /&gt;            {&lt;BR /&gt;               //do some dummy job&lt;BR /&gt;               l = pP-&amp;gt;nr;&lt;BR /&gt;               pP-&amp;gt;y = l;&lt;BR /&gt;            }&lt;BR /&gt;            pP = pP-&amp;gt;pNext;&lt;BR /&gt;         }&lt;BR /&gt;      } // end of single nowait&lt;BR /&gt;   } // end of parallel region&lt;BR /&gt;} // end of for &lt;BR /&gt;[/cpp]&lt;/PRE&gt;
&lt;BR /&gt;Complete test routine:&lt;BR /&gt;ATTENTION!: following example can block your PC.&lt;BR /&gt;&lt;BR /&gt;
&lt;PRE&gt;[cpp]#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;STDLIB.H&gt;&lt;BR /&gt;#include "omp.h"&lt;BR /&gt;&lt;BR /&gt;struct ITEM&lt;BR /&gt;{&lt;BR /&gt;  double z, y;&lt;BR /&gt;  int nr;&lt;BR /&gt;  ITEM *pNext; // pointer to next&lt;BR /&gt;  ITEM *pPrev; //pointer to previous&lt;BR /&gt;};&lt;BR /&gt;&lt;BR /&gt;/********** prot. *********/&lt;BR /&gt;void AppendItem(ITEM *pP);&lt;BR /&gt;void RemoveItem(ITEM *pP);&lt;BR /&gt;void DeleteAllItems(void);&lt;BR /&gt;&lt;BR /&gt;// Init&lt;BR /&gt;ITEM *pFirst, *pLast;&lt;BR /&gt;ITEM *pP;&lt;BR /&gt;ITEM *pTemp;&lt;BR /&gt;&lt;BR /&gt;int main()&lt;BR /&gt;{&lt;BR /&gt;  int l, i;&lt;BR /&gt;&lt;BR /&gt;  // create linked list&lt;BR /&gt;  for(l=1;l&amp;lt;=1000;l++){ &lt;BR /&gt;    pP = new ITEM; // get mem for item&lt;BR /&gt;    pP-&amp;gt;nr = l;&lt;BR /&gt;    AppendItem(pP);&lt;BR /&gt;  }&lt;BR /&gt;&lt;BR /&gt;  for(i=1;i&amp;lt;=10000;i++)&lt;BR /&gt;  {&lt;BR /&gt;    pP = pFirst;&lt;BR /&gt;    #pragma omp parallel num_threads(2)&lt;BR /&gt;    {&lt;BR /&gt;      #pragma omp single nowait&lt;BR /&gt;      {&lt;BR /&gt;        while (pP != NULL)&lt;BR /&gt;        {&lt;BR /&gt;          #pragma omp task private(l) firstprivate(pP)&lt;BR /&gt;          {&lt;BR /&gt;             //do some dummy job&lt;BR /&gt;             l = pP-&amp;gt;nr;&lt;BR /&gt;             pP-&amp;gt;y = l;&lt;BR /&gt;          }&lt;BR /&gt;          pP = pP-&amp;gt;pNext;&lt;BR /&gt;          }&lt;BR /&gt;        } // end of single nowait &lt;BR /&gt;      } // end of parallel region&lt;BR /&gt;    }&lt;BR /&gt;    DeleteAllItems();&lt;BR /&gt;    return 0;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;// Appends a node to the end of the list&lt;BR /&gt;void AppendItem(ITEM *pP)&lt;BR /&gt;{&lt;BR /&gt;  if (pFirst == NULL) {&lt;BR /&gt;    pFirst = pP;&lt;BR /&gt;    pP-&amp;gt;pPrev = NULL; &lt;BR /&gt;  }&lt;BR /&gt;  else {&lt;BR /&gt;    pLast-&amp;gt;pNext = pP;&lt;BR /&gt;    pP-&amp;gt;pPrev = pLast;&lt;BR /&gt;    }&lt;BR /&gt;  pLast = pP;&lt;BR /&gt;  pP-&amp;gt;pNext = NULL;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;// Removes the specified node from the list&lt;BR /&gt;void RemoveItem(ITEM *pP)&lt;BR /&gt;{&lt;BR /&gt;  if (pP-&amp;gt;pPrev == NULL) pFirst = pP-&amp;gt;pNext;&lt;BR /&gt;  else pP-&amp;gt;pPrev-&amp;gt;pNext = pP-&amp;gt;pNext;&lt;BR /&gt;  if (pP-&amp;gt;pNext == NULL) pLast = pP-&amp;gt;pPrev;&lt;BR /&gt;  else pP-&amp;gt;pNext-&amp;gt;pPrev = pP-&amp;gt;pPrev;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;// Deletes the entire list&lt;BR /&gt;void DeleteAllItems()&lt;BR /&gt;{&lt;BR /&gt;  while (pFirst != NULL){&lt;BR /&gt;  RemoveItem(pFirst);&lt;BR /&gt;  RemoveItem(pP);}&lt;BR /&gt;} &lt;BR /&gt;[/cpp]&lt;/STDLIB.H&gt;&lt;/STDIO.H&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 13 Apr 2009 14:20:13 GMT</pubDate>
    <dc:creator>ifx</dc:creator>
    <dc:date>2009-04-13T14:20:13Z</dc:date>
    <item>
      <title>firstprivate is hungry</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/firstprivate-is-hungry/m-p/860067#M2263</link>
      <description>Hi, &lt;BR /&gt;i am learning openmp and i want to parallelize one part of my simulation routine with linked list structure. Following some examples from the net, i modified my code, but it does not work according my expectations. The parallel part of the code is draining my memory. I need to iterate several times through the complete linked list. Every time when the "firstprivate" makes a private copy of the Item from the linked list, it is taking some part of the memory, but after the job is done and one "task" is closed, the memory is not released. Is it normal or am i doing something wrong? How can i solve this? &lt;BR /&gt;&lt;BR /&gt;thank you for your tips. test example:  (compiled with:  icc -g -O0 -openmp -o test ./test.cc )&lt;BR /&gt;&lt;BR /&gt;critical part of test routine:&lt;BR /&gt;
&lt;PRE&gt;[cpp]for(i=1;i&amp;lt;=1000;i++)  // MORE interations needs MORE memory&lt;BR /&gt;{&lt;BR /&gt;   pP = pFirst;&lt;BR /&gt;   #pragma omp parallel num_threads(2)&lt;BR /&gt;   {&lt;BR /&gt;      #pragma omp single nowait&lt;BR /&gt;      {&lt;BR /&gt;         while (pP != NULL)&lt;BR /&gt;         {&lt;BR /&gt;            #pragma omp task private(l) firstprivate(pP)&lt;BR /&gt;            {&lt;BR /&gt;               //do some dummy job&lt;BR /&gt;               l = pP-&amp;gt;nr;&lt;BR /&gt;               pP-&amp;gt;y = l;&lt;BR /&gt;            }&lt;BR /&gt;            pP = pP-&amp;gt;pNext;&lt;BR /&gt;         }&lt;BR /&gt;      } // end of single nowait&lt;BR /&gt;   } // end of parallel region&lt;BR /&gt;} // end of for &lt;BR /&gt;[/cpp]&lt;/PRE&gt;
&lt;BR /&gt;Complete test routine:&lt;BR /&gt;ATTENTION!: following example can block your PC.&lt;BR /&gt;&lt;BR /&gt;
&lt;PRE&gt;[cpp]#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;STDLIB.H&gt;&lt;BR /&gt;#include "omp.h"&lt;BR /&gt;&lt;BR /&gt;struct ITEM&lt;BR /&gt;{&lt;BR /&gt;  double z, y;&lt;BR /&gt;  int nr;&lt;BR /&gt;  ITEM *pNext; // pointer to next&lt;BR /&gt;  ITEM *pPrev; //pointer to previous&lt;BR /&gt;};&lt;BR /&gt;&lt;BR /&gt;/********** prot. *********/&lt;BR /&gt;void AppendItem(ITEM *pP);&lt;BR /&gt;void RemoveItem(ITEM *pP);&lt;BR /&gt;void DeleteAllItems(void);&lt;BR /&gt;&lt;BR /&gt;// Init&lt;BR /&gt;ITEM *pFirst, *pLast;&lt;BR /&gt;ITEM *pP;&lt;BR /&gt;ITEM *pTemp;&lt;BR /&gt;&lt;BR /&gt;int main()&lt;BR /&gt;{&lt;BR /&gt;  int l, i;&lt;BR /&gt;&lt;BR /&gt;  // create linked list&lt;BR /&gt;  for(l=1;l&amp;lt;=1000;l++){ &lt;BR /&gt;    pP = new ITEM; // get mem for item&lt;BR /&gt;    pP-&amp;gt;nr = l;&lt;BR /&gt;    AppendItem(pP);&lt;BR /&gt;  }&lt;BR /&gt;&lt;BR /&gt;  for(i=1;i&amp;lt;=10000;i++)&lt;BR /&gt;  {&lt;BR /&gt;    pP = pFirst;&lt;BR /&gt;    #pragma omp parallel num_threads(2)&lt;BR /&gt;    {&lt;BR /&gt;      #pragma omp single nowait&lt;BR /&gt;      {&lt;BR /&gt;        while (pP != NULL)&lt;BR /&gt;        {&lt;BR /&gt;          #pragma omp task private(l) firstprivate(pP)&lt;BR /&gt;          {&lt;BR /&gt;             //do some dummy job&lt;BR /&gt;             l = pP-&amp;gt;nr;&lt;BR /&gt;             pP-&amp;gt;y = l;&lt;BR /&gt;          }&lt;BR /&gt;          pP = pP-&amp;gt;pNext;&lt;BR /&gt;          }&lt;BR /&gt;        } // end of single nowait &lt;BR /&gt;      } // end of parallel region&lt;BR /&gt;    }&lt;BR /&gt;    DeleteAllItems();&lt;BR /&gt;    return 0;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;// Appends a node to the end of the list&lt;BR /&gt;void AppendItem(ITEM *pP)&lt;BR /&gt;{&lt;BR /&gt;  if (pFirst == NULL) {&lt;BR /&gt;    pFirst = pP;&lt;BR /&gt;    pP-&amp;gt;pPrev = NULL; &lt;BR /&gt;  }&lt;BR /&gt;  else {&lt;BR /&gt;    pLast-&amp;gt;pNext = pP;&lt;BR /&gt;    pP-&amp;gt;pPrev = pLast;&lt;BR /&gt;    }&lt;BR /&gt;  pLast = pP;&lt;BR /&gt;  pP-&amp;gt;pNext = NULL;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;// Removes the specified node from the list&lt;BR /&gt;void RemoveItem(ITEM *pP)&lt;BR /&gt;{&lt;BR /&gt;  if (pP-&amp;gt;pPrev == NULL) pFirst = pP-&amp;gt;pNext;&lt;BR /&gt;  else pP-&amp;gt;pPrev-&amp;gt;pNext = pP-&amp;gt;pNext;&lt;BR /&gt;  if (pP-&amp;gt;pNext == NULL) pLast = pP-&amp;gt;pPrev;&lt;BR /&gt;  else pP-&amp;gt;pNext-&amp;gt;pPrev = pP-&amp;gt;pPrev;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;// Deletes the entire list&lt;BR /&gt;void DeleteAllItems()&lt;BR /&gt;{&lt;BR /&gt;  while (pFirst != NULL){&lt;BR /&gt;  RemoveItem(pFirst);&lt;BR /&gt;  RemoveItem(pP);}&lt;BR /&gt;} &lt;BR /&gt;[/cpp]&lt;/STDLIB.H&gt;&lt;/STDIO.H&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Apr 2009 14:20:13 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/firstprivate-is-hungry/m-p/860067#M2263</guid>
      <dc:creator>ifx</dc:creator>
      <dc:date>2009-04-13T14:20:13Z</dc:date>
    </item>
    <item>
      <title>Re: firstprivate is hungry</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/firstprivate-is-hungry/m-p/860068#M2264</link>
      <description>&lt;DIV style="margin:0px;"&gt;
&lt;DIV id="quote_reply" style="margin-top: 5px; width: 100%;"&gt;
&lt;DIV style="margin-left:2px;margin-right:2px;"&gt;Quoting - &lt;A href="https://community.intel.com/en-us/profile/423206"&gt;ifx&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="background-color:#E5E5E5; padding:5px;border: 1px; border-style: inset;margin-left:2px;margin-right:2px;"&gt;&lt;EM&gt;Hi, &lt;BR /&gt;i am learning openmp and i want to parallelize one part of my simulation routine with linked list structure. Following some examples from the net, i modified my code, but it does not work according my expectations. The parallel part of the code is draining my memory. I need to iterate several times through the complete linked list. Every time when the "firstprivate" makes a private copy of the Item from the linked list, it is taking some part of the memory, but after the job is done and one "task" is closed, the memory is not released. Is it normal or am i doing something wrong? How can i solve this? &lt;BR /&gt;&lt;BR /&gt;thank you for your tips. test example: (compiled with: icc -g -O0 -openmp -o test ./test.cc )&lt;BR /&gt;&lt;BR /&gt;critical part of test routine:&lt;BR /&gt;
&lt;/EM&gt;&lt;PRE&gt;&lt;EM&gt;[cpp]for(i=1;i&amp;lt;=1000;i++)  // MORE interations needs MORE memory&lt;BR /&gt;{&lt;BR /&gt;   pP = pFirst;&lt;BR /&gt;   #pragma omp parallel num_threads(2)&lt;BR /&gt;   {&lt;BR /&gt;      #pragma omp single nowait&lt;BR /&gt;      {&lt;BR /&gt;         while (pP != NULL)&lt;BR /&gt;         {&lt;BR /&gt;            #pragma omp task private(l) firstprivate(pP)&lt;BR /&gt;            {&lt;BR /&gt;               //do some dummy job&lt;BR /&gt;               l = pP-&amp;gt;nr;&lt;BR /&gt;               pP-&amp;gt;y = l;&lt;BR /&gt;            }&lt;BR /&gt;            pP = pP-&amp;gt;pNext;&lt;BR /&gt;         }&lt;BR /&gt;      } // end of single nowait&lt;BR /&gt;   } // end of parallel region&lt;BR /&gt;} // end of for &lt;BR /&gt;[/cpp]&lt;/EM&gt;&lt;/PRE&gt;
&lt;BR /&gt;Complete test routine:&lt;BR /&gt;ATTENTION!: following example can block your PC.&lt;BR /&gt;&lt;BR /&gt;
&lt;PRE&gt;[cpp]#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;STDLIB.H&gt;&lt;BR /&gt;#include "omp.h"&lt;BR /&gt;&lt;BR /&gt;struct ITEM&lt;BR /&gt;{&lt;BR /&gt;  double z, y;&lt;BR /&gt;  int nr;&lt;BR /&gt;  ITEM *pNext; // pointer to next&lt;BR /&gt;  ITEM *pPrev; //pointer to previous&lt;BR /&gt;};&lt;BR /&gt;&lt;BR /&gt;/********** prot. *********/&lt;BR /&gt;void AppendItem(ITEM *pP);&lt;BR /&gt;void RemoveItem(ITEM *pP);&lt;BR /&gt;void DeleteAllItems(void);&lt;BR /&gt;&lt;BR /&gt;// Init&lt;BR /&gt;ITEM *pFirst, *pLast;&lt;BR /&gt;ITEM *pP;&lt;BR /&gt;ITEM *pTemp;&lt;BR /&gt;&lt;BR /&gt;int main()&lt;BR /&gt;{&lt;BR /&gt;  int l, i;&lt;BR /&gt;&lt;BR /&gt;  // create linked list&lt;BR /&gt;  for(l=1;l&amp;lt;=1000;l++){ &lt;BR /&gt;    pP = new ITEM; // get mem for item&lt;BR /&gt;    pP-&amp;gt;nr = l;&lt;BR /&gt;    AppendItem(pP);&lt;BR /&gt;  }&lt;BR /&gt;&lt;BR /&gt;  for(i=1;i&amp;lt;=10000;i++)&lt;BR /&gt;  {&lt;BR /&gt;    pP = pFirst;&lt;BR /&gt;    #pragma omp parallel num_threads(2)&lt;BR /&gt;    {&lt;BR /&gt;      #pragma omp single nowait&lt;BR /&gt;      {&lt;BR /&gt;        while (pP != NULL)&lt;BR /&gt;        {&lt;BR /&gt;          #pragma omp task private(l) firstprivate(pP)&lt;BR /&gt;          {&lt;BR /&gt;             //do some dummy job&lt;BR /&gt;             l = pP-&amp;gt;nr;&lt;BR /&gt;             pP-&amp;gt;y = l;&lt;BR /&gt;          }&lt;BR /&gt;          pP = pP-&amp;gt;pNext;&lt;BR /&gt;          }&lt;BR /&gt;        } // end of single nowait &lt;BR /&gt;      } // end of parallel region&lt;BR /&gt;    }&lt;BR /&gt;    DeleteAllItems();&lt;BR /&gt;    return 0;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;// Appends a node to the end of the list&lt;BR /&gt;void AppendItem(ITEM *pP)&lt;BR /&gt;{&lt;BR /&gt;  if (pFirst == NULL) {&lt;BR /&gt;    pFirst = pP;&lt;BR /&gt;    pP-&amp;gt;pPrev = NULL; &lt;BR /&gt;  }&lt;BR /&gt;  else {&lt;BR /&gt;    pLast-&amp;gt;pNext = pP;&lt;BR /&gt;    pP-&amp;gt;pPrev = pLast;&lt;BR /&gt;    }&lt;BR /&gt;  pLast = pP;&lt;BR /&gt;  pP-&amp;gt;pNext = NULL;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;// Removes the specified node from the list&lt;BR /&gt;void RemoveItem(ITEM *pP)&lt;BR /&gt;{&lt;BR /&gt;  if (pP-&amp;gt;pPrev == NULL) pFirst = pP-&amp;gt;pNext;&lt;BR /&gt;  else pP-&amp;gt;pPrev-&amp;gt;pNext = pP-&amp;gt;pNext;&lt;BR /&gt;  if (pP-&amp;gt;pNext == NULL) pLast = pP-&amp;gt;pPrev;&lt;BR /&gt;  else pP-&amp;gt;pNext-&amp;gt;pPrev = pP-&amp;gt;pPrev;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;// Deletes the entire list&lt;BR /&gt;void DeleteAllItems()&lt;BR /&gt;{&lt;BR /&gt;  while (pFirst != NULL){&lt;BR /&gt;  RemoveItem(pFirst);&lt;BR /&gt;  RemoveItem(pP);}&lt;BR /&gt;} &lt;BR /&gt;[/cpp]&lt;/STDLIB.H&gt;&lt;/STDIO.H&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;BR /&gt;I think you have discovered an issue with Intel C++ compiler. &lt;BR /&gt;&lt;BR /&gt;Also you are missing "delete pP;" inRemoveItem().I think you need to remove the statement "RemoveItem(pP);" from DeleteAllItems().&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 14 Apr 2009 06:29:04 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/firstprivate-is-hungry/m-p/860068#M2264</guid>
      <dc:creator>Om_S_Intel</dc:creator>
      <dc:date>2009-04-14T06:29:04Z</dc:date>
    </item>
  </channel>
</rss>

