<?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 How can I  Use C Reducer? in Software Archive</title>
    <link>https://community.intel.com/t5/Software-Archive/How-can-I-Use-C-Reducer/m-p/740523#M229</link>
    <description>Hello,&lt;BR /&gt;&lt;BR /&gt;a working version would look like this:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE&gt;[cpp]#include &lt;STDIO.H&gt;
#include &lt;TIME.H&gt;
#include &lt;CILK&gt;
#include &lt;CILK&gt;
#include &lt;CILK&gt;
#include &lt;CILK&gt;

void MakeRandData(unsigned int* pData, unsigned int nSize)
{

    srand((unsigned int)time(NULL));

    for(unsigned int i =0; i &amp;lt; nSize; i++)
        pData&lt;I&gt; = 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  &amp;lt; nSize; i++)
    {
        if(pData&lt;I&gt; &amp;gt; REDUCER_VIEW(re_nMaxIndex).value)
        {
            CILK_C_REDUCER_MAX_INDEX_CALC(re_nMaxIndex, i, pData&lt;I&gt;);
        }
    }

    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(&amp;amp;pNData[0], MAX_COUNT);
    nFindMaxPos = FindMaxIndex(&amp;amp;pNData[0], MAX_COUNT);
    printf("max value posision is %d.rn",nFindMaxPos);

    delete [] pNData;

    return 0;
}
[/cpp]&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/CILK&gt;&lt;/CILK&gt;&lt;/CILK&gt;&lt;/CILK&gt;&lt;/TIME.H&gt;&lt;/STDIO.H&gt;&lt;/PRE&gt; Please note:&lt;BR /&gt;i) Reducers need to be registered and unregistered.&lt;BR /&gt;ii) &lt;I&gt;CILK_C_REDUCER_MAX_INDEX&lt;/I&gt; contains both index &amp;amp; value.&lt;BR /&gt;iii) Basic reducer types are already predefined for basic C numeric types (unsigned int for values -&amp;gt; uint as reducer type). See headers (&lt;I&gt;reducer_*.h&lt;/I&gt;) for list of all types.&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;You'll find more information here: &lt;A href="http://software.intel.com/en-us/articles/using-an-intel-cilk-plus-reducer-in-c/"&gt;http://software.intel.com/en-us/articles/using-an-intel-cilk-plus-reducer-in-c/&lt;/A&gt;.&lt;BR /&gt;&lt;BR /&gt;Best regards,&lt;BR /&gt;&lt;BR /&gt;Georg Zitzlsberger</description>
    <pubDate>Thu, 15 Dec 2011 17:29:54 GMT</pubDate>
    <dc:creator>Georg_Z_Intel</dc:creator>
    <dc:date>2011-12-15T17:29:54Z</dc:date>
    <item>
      <title>How can I  Use C Reducer?</title>
      <link>https://community.intel.com/t5/Software-Archive/How-can-I-Use-C-Reducer/m-p/740522#M228</link>
      <description>&lt;P&gt;I want to use C Reducer. &lt;BR /&gt;&lt;BR /&gt;I write this code.&lt;BR /&gt;&lt;BR /&gt;-----------------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;PRE&gt;[cpp]#include &lt;STDIO.H&gt;
#include &lt;IOSTREAM&gt;
#include &lt;TIME.H&gt;
#include &lt;CILK&gt;
#include &lt;CILK&gt;
#include &lt;CILK&gt;
#include &lt;CILK&gt;

void MakeRandData(unsigned int* pData, unsigned int nSize)
{        

	srand((unsigned int)time(NULL));

	for(unsigned int i =0; i &amp;lt; nSize; i++)
		pData&lt;I&gt; = 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  &amp;lt; nSize; i++)
	{
		if(pData&lt;I&gt; &amp;gt; REDUCER_VIEW(re_nMax))
		{
			REDUCER_VIEW(re_nMax) = pData&lt;I&gt;;
			&lt;STRONG&gt;REDUCER_VIEW(re_nIndex) = i; // error&lt;/STRONG&gt;
		}
	}

	&lt;STRONG&gt;re_nIndex = REDUCER_VIEW(re_nIndex); //error&lt;/STRONG&gt;
	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(&amp;amp;pNData[0], MAX_COUNT);
	nFindMaxPos = FindMaxIndex(&amp;amp;pNData[0], MAX_COUNT);
	printf("max value posision is %d.\r\n",nFindMaxPos);

	delete [] pNData;

	return 0;
}[/cpp]&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/CILK&gt;&lt;/CILK&gt;&lt;/CILK&gt;&lt;/CILK&gt;&lt;/TIME.H&gt;&lt;/IOSTREAM&gt;&lt;/STDIO.H&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;-----------------------------------------------------------------------------------------------------------------------------&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;this program occur error!&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;I don't understand. why do this program occur error?&lt;BR /&gt;&lt;BR /&gt;How can I successfully this program&lt;/P&gt;</description>
      <pubDate>Fri, 14 Oct 2011 17:18:33 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/How-can-I-Use-C-Reducer/m-p/740522#M228</guid>
      <dc:creator>dalgunim</dc:creator>
      <dc:date>2011-10-14T17:18:33Z</dc:date>
    </item>
    <item>
      <title>How can I  Use C Reducer?</title>
      <link>https://community.intel.com/t5/Software-Archive/How-can-I-Use-C-Reducer/m-p/740523#M229</link>
      <description>Hello,&lt;BR /&gt;&lt;BR /&gt;a working version would look like this:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE&gt;[cpp]#include &lt;STDIO.H&gt;
#include &lt;TIME.H&gt;
#include &lt;CILK&gt;
#include &lt;CILK&gt;
#include &lt;CILK&gt;
#include &lt;CILK&gt;

void MakeRandData(unsigned int* pData, unsigned int nSize)
{

    srand((unsigned int)time(NULL));

    for(unsigned int i =0; i &amp;lt; nSize; i++)
        pData&lt;I&gt; = 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  &amp;lt; nSize; i++)
    {
        if(pData&lt;I&gt; &amp;gt; REDUCER_VIEW(re_nMaxIndex).value)
        {
            CILK_C_REDUCER_MAX_INDEX_CALC(re_nMaxIndex, i, pData&lt;I&gt;);
        }
    }

    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(&amp;amp;pNData[0], MAX_COUNT);
    nFindMaxPos = FindMaxIndex(&amp;amp;pNData[0], MAX_COUNT);
    printf("max value posision is %d.rn",nFindMaxPos);

    delete [] pNData;

    return 0;
}
[/cpp]&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/CILK&gt;&lt;/CILK&gt;&lt;/CILK&gt;&lt;/CILK&gt;&lt;/TIME.H&gt;&lt;/STDIO.H&gt;&lt;/PRE&gt; Please note:&lt;BR /&gt;i) Reducers need to be registered and unregistered.&lt;BR /&gt;ii) &lt;I&gt;CILK_C_REDUCER_MAX_INDEX&lt;/I&gt; contains both index &amp;amp; value.&lt;BR /&gt;iii) Basic reducer types are already predefined for basic C numeric types (unsigned int for values -&amp;gt; uint as reducer type). See headers (&lt;I&gt;reducer_*.h&lt;/I&gt;) for list of all types.&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;You'll find more information here: &lt;A href="http://software.intel.com/en-us/articles/using-an-intel-cilk-plus-reducer-in-c/"&gt;http://software.intel.com/en-us/articles/using-an-intel-cilk-plus-reducer-in-c/&lt;/A&gt;.&lt;BR /&gt;&lt;BR /&gt;Best regards,&lt;BR /&gt;&lt;BR /&gt;Georg Zitzlsberger</description>
      <pubDate>Thu, 15 Dec 2011 17:29:54 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/How-can-I-Use-C-Reducer/m-p/740523#M229</guid>
      <dc:creator>Georg_Z_Intel</dc:creator>
      <dc:date>2011-12-15T17:29:54Z</dc:date>
    </item>
    <item>
      <title>How can I  Use C Reducer?</title>
      <link>https://community.intel.com/t5/Software-Archive/How-can-I-Use-C-Reducer/m-p/740524#M230</link>
      <description>&lt;P&gt;Thank you very so much.&lt;/P&gt;&lt;P&gt;I solve this problem!&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jan 2012 05:57:59 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/How-can-I-Use-C-Reducer/m-p/740524#M230</guid>
      <dc:creator>dalgunim</dc:creator>
      <dc:date>2012-01-11T05:57:59Z</dc:date>
    </item>
  </channel>
</rss>

