- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I want to use C Reducer.
I write this code.
-----------------------------------------------------------------------------------------------------------------------------
[cpp]#include#include #include #include #include #include #include void MakeRandData(unsigned int* pData, unsigned int nSize) { srand((unsigned int)time(NULL)); for(unsigned int i =0; i < nSize; i++) pData = rand()%(nSize-1); unsigned int nMsxPos= rand()%(nSize); pData[nMsxPos] = nSize; printf("Max value po %d.\r\n",nMsxPos); } int FindMaxIndex(unsigned int* pData, unsigned int nSize) { int nMax = 0, nFindIndex = 0; CILK_C_REDUCER_MAX_INDEX(re_nIndex,int, -1); CILK_C_REDUCER_MAX(re_nMax, int, 0); cilk_for(int i =0; i < nSize; i++) { if(pData > REDUCER_VIEW(re_nMax)) { REDUCER_VIEW(re_nMax) = pData; REDUCER_VIEW(re_nIndex) = i; // error } } re_nIndex = REDUCER_VIEW(re_nIndex); //error nMax = REDUCER_VIEW(re_nMax); return nFindIndex; } int _tmain(int argc, _TCHAR* argv[]) { const unsigned int MAX_COUNT = 100000000; unsigned int* pNData; unsigned int nFindMaxPos; pNData = new unsigned int [MAX_COUNT]; MakeRandData(&pNData[0], MAX_COUNT); nFindMaxPos = FindMaxIndex(&pNData[0], MAX_COUNT); printf("max value posision is %d.\r\n",nFindMaxPos); delete [] pNData; return 0; }[/cpp]
-----------------------------------------------------------------------------------------------------------------------------
this program occur error!
I don't understand. why do this program occur error?
How can I successfully this program
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
a working version would look like this:
i) Reducers need to be registered and unregistered.
ii) CILK_C_REDUCER_MAX_INDEX contains both index & value.
iii) Basic reducer types are already predefined for basic C numeric types (unsigned int for values -> uint as reducer type). See headers (reducer_*.h) for list of all types.
iv) This is not real plain C99 code because of new/delete. Anyways, the exercise was for understanding C reducers if I get it right.
You'll find more information here: http://software.intel.com/en-us/articles/using-an-intel-cilk-plus-reducer-in-c/.
Best regards,
Georg Zitzlsberger
a working version would look like this:
[cpp]#includePlease note:#include #include #include #include #include void MakeRandData(unsigned int* pData, unsigned int nSize) { srand((unsigned int)time(NULL)); for(unsigned int i =0; i < nSize; i++) pData = rand()%(nSize-1); unsigned int nMsxPos= rand()%(nSize); pData[nMsxPos] = nSize; printf("Max value po %d.rn",nMsxPos); } int FindMaxIndex(unsigned int* pData, unsigned int nSize) { int nMax = 0, nFindIndex = 0; CILK_C_REDUCER_MAX_INDEX(re_nMaxIndex, uint, 0); // max. value with index! CILK_C_REGISTER_REDUCER(re_nMaxIndex); cilk_for(int i =0; i < nSize; i++) { if(pData > REDUCER_VIEW(re_nMaxIndex).value) { CILK_C_REDUCER_MAX_INDEX_CALC(re_nMaxIndex, i, pData); } } nFindIndex = REDUCER_VIEW(re_nMaxIndex).index; CILK_C_UNREGISTER_REDUCER(re_nMaxIndex); return nFindIndex; } int main(int argc, char* argv[]) { const unsigned int MAX_COUNT = 100000000; unsigned int* pNData; unsigned int nFindMaxPos; pNData = new unsigned int [MAX_COUNT]; MakeRandData(&pNData[0], MAX_COUNT); nFindMaxPos = FindMaxIndex(&pNData[0], MAX_COUNT); printf("max value posision is %d.rn",nFindMaxPos); delete [] pNData; return 0; } [/cpp]
i) Reducers need to be registered and unregistered.
ii) CILK_C_REDUCER_MAX_INDEX contains both index & value.
iii) Basic reducer types are already predefined for basic C numeric types (unsigned int for values -> uint as reducer type). See headers (reducer_*.h) for list of all types.
iv) This is not real plain C99 code because of new/delete. Anyways, the exercise was for understanding C reducers if I get it right.
You'll find more information here: http://software.intel.com/en-us/articles/using-an-intel-cilk-plus-reducer-in-c/.
Best regards,
Georg Zitzlsberger
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
a working version would look like this:
i) Reducers need to be registered and unregistered.
ii) CILK_C_REDUCER_MAX_INDEX contains both index & value.
iii) Basic reducer types are already predefined for basic C numeric types (unsigned int for values -> uint as reducer type). See headers (reducer_*.h) for list of all types.
iv) This is not real plain C99 code because of new/delete. Anyways, the exercise was for understanding C reducers if I get it right.
You'll find more information here: http://software.intel.com/en-us/articles/using-an-intel-cilk-plus-reducer-in-c/.
Best regards,
Georg Zitzlsberger
a working version would look like this:
[cpp]#includePlease note:#include #include #include #include #include void MakeRandData(unsigned int* pData, unsigned int nSize) { srand((unsigned int)time(NULL)); for(unsigned int i =0; i < nSize; i++) pData = rand()%(nSize-1); unsigned int nMsxPos= rand()%(nSize); pData[nMsxPos] = nSize; printf("Max value po %d.rn",nMsxPos); } int FindMaxIndex(unsigned int* pData, unsigned int nSize) { int nMax = 0, nFindIndex = 0; CILK_C_REDUCER_MAX_INDEX(re_nMaxIndex, uint, 0); // max. value with index! CILK_C_REGISTER_REDUCER(re_nMaxIndex); cilk_for(int i =0; i < nSize; i++) { if(pData > REDUCER_VIEW(re_nMaxIndex).value) { CILK_C_REDUCER_MAX_INDEX_CALC(re_nMaxIndex, i, pData); } } nFindIndex = REDUCER_VIEW(re_nMaxIndex).index; CILK_C_UNREGISTER_REDUCER(re_nMaxIndex); return nFindIndex; } int main(int argc, char* argv[]) { const unsigned int MAX_COUNT = 100000000; unsigned int* pNData; unsigned int nFindMaxPos; pNData = new unsigned int [MAX_COUNT]; MakeRandData(&pNData[0], MAX_COUNT); nFindMaxPos = FindMaxIndex(&pNData[0], MAX_COUNT); printf("max value posision is %d.rn",nFindMaxPos); delete [] pNData; return 0; } [/cpp]
i) Reducers need to be registered and unregistered.
ii) CILK_C_REDUCER_MAX_INDEX contains both index & value.
iii) Basic reducer types are already predefined for basic C numeric types (unsigned int for values -> uint as reducer type). See headers (reducer_*.h) for list of all types.
iv) This is not real plain C99 code because of new/delete. Anyways, the exercise was for understanding C reducers if I get it right.
You'll find more information here: http://software.intel.com/en-us/articles/using-an-intel-cilk-plus-reducer-in-c/.
Best regards,
Georg Zitzlsberger
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you very so much.
I solve this problem!

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