- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
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?
thank you for your tips. test example: (compiled with: icc -g -O0 -openmp -o test ./test.cc )
critical part of test routine:
Complete test routine:
ATTENTION!: following example can block your PC.
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?
thank you for your tips. test example: (compiled with: icc -g -O0 -openmp -o test ./test.cc )
critical part of test routine:
[cpp]for(i=1;i<=1000;i++) // MORE interations needs MORE memory
{
pP = pFirst;
#pragma omp parallel num_threads(2)
{
#pragma omp single nowait
{
while (pP != NULL)
{
#pragma omp task private(l) firstprivate(pP)
{
//do some dummy job
l = pP->nr;
pP->y = l;
}
pP = pP->pNext;
}
} // end of single nowait
} // end of parallel region
} // end of for
[/cpp]
Complete test routine:
ATTENTION!: following example can block your PC.
[cpp]#include
#include
#include "omp.h"
struct ITEM
{
double z, y;
int nr;
ITEM *pNext; // pointer to next
ITEM *pPrev; //pointer to previous
};
/********** prot. *********/
void AppendItem(ITEM *pP);
void RemoveItem(ITEM *pP);
void DeleteAllItems(void);
// Init
ITEM *pFirst, *pLast;
ITEM *pP;
ITEM *pTemp;
int main()
{
int l, i;
// create linked list
for(l=1;l<=1000;l++){
pP = new ITEM; // get mem for item
pP->nr = l;
AppendItem(pP);
}
for(i=1;i<=10000;i++)
{
pP = pFirst;
#pragma omp parallel num_threads(2)
{
#pragma omp single nowait
{
while (pP != NULL)
{
#pragma omp task private(l) firstprivate(pP)
{
//do some dummy job
l = pP->nr;
pP->y = l;
}
pP = pP->pNext;
}
} // end of single nowait
} // end of parallel region
}
DeleteAllItems();
return 0;
}
// Appends a node to the end of the list
void AppendItem(ITEM *pP)
{
if (pFirst == NULL) {
pFirst = pP;
pP->pPrev = NULL;
}
else {
pLast->pNext = pP;
pP->pPrev = pLast;
}
pLast = pP;
pP->pNext = NULL;
}
// Removes the specified node from the list
void RemoveItem(ITEM *pP)
{
if (pP->pPrev == NULL) pFirst = pP->pNext;
else pP->pPrev->pNext = pP->pNext;
if (pP->pNext == NULL) pLast = pP->pPrev;
else pP->pNext->pPrev = pP->pPrev;
}
// Deletes the entire list
void DeleteAllItems()
{
while (pFirst != NULL){
RemoveItem(pFirst);
RemoveItem(pP);}
}
[/cpp]
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - ifx
Hi,
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?
thank you for your tips. test example: (compiled with: icc -g -O0 -openmp -o test ./test.cc )
critical part of test routine:
Complete test routine:
ATTENTION!: following example can block your PC.
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?
thank you for your tips. test example: (compiled with: icc -g -O0 -openmp -o test ./test.cc )
critical part of test routine:
[cpp]for(i=1;i<=1000;i++) // MORE interations needs MORE memory
{
pP = pFirst;
#pragma omp parallel num_threads(2)
{
#pragma omp single nowait
{
while (pP != NULL)
{
#pragma omp task private(l) firstprivate(pP)
{
//do some dummy job
l = pP->nr;
pP->y = l;
}
pP = pP->pNext;
}
} // end of single nowait
} // end of parallel region
} // end of for
[/cpp]
Complete test routine:
ATTENTION!: following example can block your PC.
[cpp]#include
#include
#include "omp.h"
struct ITEM
{
double z, y;
int nr;
ITEM *pNext; // pointer to next
ITEM *pPrev; //pointer to previous
};
/********** prot. *********/
void AppendItem(ITEM *pP);
void RemoveItem(ITEM *pP);
void DeleteAllItems(void);
// Init
ITEM *pFirst, *pLast;
ITEM *pP;
ITEM *pTemp;
int main()
{
int l, i;
// create linked list
for(l=1;l<=1000;l++){
pP = new ITEM; // get mem for item
pP->nr = l;
AppendItem(pP);
}
for(i=1;i<=10000;i++)
{
pP = pFirst;
#pragma omp parallel num_threads(2)
{
#pragma omp single nowait
{
while (pP != NULL)
{
#pragma omp task private(l) firstprivate(pP)
{
//do some dummy job
l = pP->nr;
pP->y = l;
}
pP = pP->pNext;
}
} // end of single nowait
} // end of parallel region
}
DeleteAllItems();
return 0;
}
// Appends a node to the end of the list
void AppendItem(ITEM *pP)
{
if (pFirst == NULL) {
pFirst = pP;
pP->pPrev = NULL;
}
else {
pLast->pNext = pP;
pP->pPrev = pLast;
}
pLast = pP;
pP->pNext = NULL;
}
// Removes the specified node from the list
void RemoveItem(ITEM *pP)
{
if (pP->pPrev == NULL) pFirst = pP->pNext;
else pP->pPrev->pNext = pP->pNext;
if (pP->pNext == NULL) pLast = pP->pPrev;
else pP->pNext->pPrev = pP->pPrev;
}
// Deletes the entire list
void DeleteAllItems()
{
while (pFirst != NULL){
RemoveItem(pFirst);
RemoveItem(pP);}
}
[/cpp]
I think you have discovered an issue with Intel C++ compiler.
Also you are missing "delete pP;" inRemoveItem().I think you need to remove the statement "RemoveItem(pP);" from DeleteAllItems().
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page