<?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 kmp_set_affinity_mask_proc in Intel® Moderncode for Parallel Architectures</title>
    <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/kmp-set-affinity-4-new-omp-mask-return-error-22/m-p/1173095#M8021</link>
    <description>&lt;P&gt;kmp_set_affinity_mask_proc(int LogicalProcessorNumberBitToSet, kmp_affinity_mask_t* mask);&lt;/P&gt;

&lt;P&gt;Your line 14 is hard to interpret what you intentions are - please explain what you are trying to do.&lt;/P&gt;

&lt;P&gt;Note, If the last thread team member number of the parallel region is the (near) the highest logical processor number of the system (available to your process), then "+ core_num" will likely index beyond the bits available to the affinity bit mask. This may corrupt memory or set unavailable logical processor bits in reserved bits of the mask.&lt;/P&gt;

&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
    <pubDate>Thu, 14 Dec 2017 16:37:24 GMT</pubDate>
    <dc:creator>jimdempseyatthecove</dc:creator>
    <dc:date>2017-12-14T16:37:24Z</dc:date>
    <item>
      <title>kmp_set_affinity(4,&amp;new_omp_mask) return error 22</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/kmp-set-affinity-4-new-omp-mask-return-error-22/m-p/1173094#M8020</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;

&lt;P&gt;one&amp;nbsp;of our&amp;nbsp;customer reported, they&amp;nbsp;had tried do the omp affinity bind in pthread code on xeon skx server&amp;nbsp; 32core.&amp;nbsp; intel libiomp5.so&amp;nbsp; 2018 version,&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;static void test(int thread_num, int core_num) {

int num = omp_get_num_threads();
omp_set_num_threads(thread_num);

#pragma omp parallel default (shared)
&amp;nbsp;{
&amp;nbsp; int ompTid = omp_get_thread_num();
&amp;nbsp;

&amp;nbsp; kmp_affinity_mask_t new_omp_mask;
&amp;nbsp; kmp_create_affinity_mask(&amp;amp;new_omp_mask);
&amp;nbsp; kmp_set_affinity_mask_proc(ompTid, &amp;amp;new_omp_mask);
&amp;nbsp; kmp_set_affinity_mask_proc(ompTid + core_num, &amp;amp;new_omp_mask);
&amp;nbsp;
int ret = kmp_set_affinity(&amp;amp;new_omp_mask)

&amp;nbsp; if(ret != 0 ) {
&amp;nbsp;&amp;nbsp; printf("Error::kmp_set_affinity() for thread %d,&amp;nbsp; ret %d \n", ompTid, ret);
&amp;nbsp; }
}

}
&lt;/PRE&gt;

&lt;P&gt;and it give the error&amp;nbsp; Error: KMP_Set_affnity(8, ret 22)&lt;/P&gt;

&lt;P&gt;I check intel Compiler , haven't found the error message about 22, could you please tell what is exact mean of error 22.&amp;nbsp; we haven't test code,&amp;nbsp;just get the error message, so any suggest to debug the issue are appreciated.&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;

&lt;P&gt;Ying&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Dec 2017 03:37:55 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/kmp-set-affinity-4-new-omp-mask-return-error-22/m-p/1173094#M8020</guid>
      <dc:creator>Ying_H_Intel</dc:creator>
      <dc:date>2017-12-14T03:37:55Z</dc:date>
    </item>
    <item>
      <title>kmp_set_affinity_mask_proc</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/kmp-set-affinity-4-new-omp-mask-return-error-22/m-p/1173095#M8021</link>
      <description>&lt;P&gt;kmp_set_affinity_mask_proc(int LogicalProcessorNumberBitToSet, kmp_affinity_mask_t* mask);&lt;/P&gt;

&lt;P&gt;Your line 14 is hard to interpret what you intentions are - please explain what you are trying to do.&lt;/P&gt;

&lt;P&gt;Note, If the last thread team member number of the parallel region is the (near) the highest logical processor number of the system (available to your process), then "+ core_num" will likely index beyond the bits available to the affinity bit mask. This may corrupt memory or set unavailable logical processor bits in reserved bits of the mask.&lt;/P&gt;

&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Thu, 14 Dec 2017 16:37:24 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/kmp-set-affinity-4-new-omp-mask-return-error-22/m-p/1173095#M8021</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2017-12-14T16:37:24Z</dc:date>
    </item>
    <item>
      <title>Hi Jim,</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/kmp-set-affinity-4-new-omp-mask-return-error-22/m-p/1173096#M8022</link>
      <description>&lt;P&gt;Hi Jim,&lt;BR /&gt;
	​thank you for your checking.&lt;/P&gt;

&lt;P&gt;I'm not sure what purpose of the line 14, just guess,&amp;nbsp;the user&amp;nbsp;may want to handle the module&amp;nbsp; (like ompTid % &lt;FONT face="Courier New"&gt;core_num). we get some new information by export KMP_AFFINITY=verbose.&amp;nbsp;it shows that&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;

&lt;P&gt;OMP: Info #204: KMP_AFFINITY: decoding x2APIC ids.&lt;BR /&gt;
	OMP: Info #202: KMP_AFFINITY: Affinity capable, using global cpuid leaf 11 info&lt;BR /&gt;
	OMP: Info #154: KMP_AFFINITY: Initial OS proc set respected: {&lt;STRONG&gt;16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,48,49&lt;/STRONG&gt;,50,51,52,53,54,55,56,57,58,59,60,61,62,63}&lt;BR /&gt;
	OMP: Info #156: KMP_AFFINITY: 32 available OS procs&lt;BR /&gt;
	OMP: Info #157: KMP_AFFINITY: Uniform topology&lt;BR /&gt;
	OMP: Info #179: KMP_AFFINITY: 1 packages x 16 cores/pkg x 2 threads/core (16 total cores)&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp;&amp;nbsp; OMP: Info #242: KMP_AFFINITY: pid 1390 tid 1390 thread 0 bound to OS proc set {16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63}&lt;BR /&gt;
	OMP: Info #242: KMP_AFFINITY: pid 1390 tid 1431 thread 1 bound to OS proc set {16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63}&lt;BR /&gt;
	OMP: Info #242: KMP_AFFINITY: pid 1390 tid 1432 thread 2 bound to OS proc set&lt;BR /&gt;
	KMP_AFFINITY: pid 1390 tid 1472 thread 38 bound to OS proc set {16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63}&lt;BR /&gt;
	Debug: &lt;STRONG&gt;thread_num 16, core_num 32, ompTid 0, ompTid + core_num 32&lt;/STRONG&gt;&lt;BR /&gt;
	Error: &lt;STRONG&gt;kmp_set_affinity(0, &amp;amp;new_omp_mask) ret 22&lt;/STRONG&gt;&lt;BR /&gt;
	OMP: Info #242: KMP_AFFINITY: pid 1390 tid 1467 thread 34 bound to OS proc set&lt;/P&gt;

&lt;P&gt;Thus the problem seems that the OS proc ID is &lt;STRONG&gt;not&amp;nbsp; from 1 - 32 core, but &lt;/STRONG&gt;&lt;B&gt;16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,48,49&lt;/B&gt;,50,51,52,53,54,55,56,57,58,59,60,61,62,63}&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;.&amp;nbsp;&amp;nbsp;&amp;nbsp;while in the kmp_set_affinity_mask_proc,&amp;nbsp;we suppose int LogicalProcessorNumberBitToSet​ is from&amp;nbsp; &lt;SPAN style="margin: 0px; color: rgb(31, 73, 125); font-family: &amp;quot;Calibri&amp;quot;,sans-serif; font-size: 11pt;"&gt;omp&amp;nbsp;0 to&amp;nbsp; os proc 15. &lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="margin: 0px; color: rgb(31, 73, 125); font-family: &amp;quot;Calibri&amp;quot;,sans-serif; font-size: 11pt;"&gt;​Maybe to use the system affinity will workaround the problem. ask user to try and will feedback if it works&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN class="fontstyle0"&gt;&lt;FONT color="#333333" face="Courier" size="2"&gt;CPU_ZERO(&amp;amp;new_mask);&lt;BR /&gt;
	CPU_SET(ompTid, &amp;amp;new_mask);&lt;BR /&gt;
	if (sched_getaffinity(0, sizeof(was_mask), &amp;amp;was_mask)&lt;BR /&gt;
	== -1) {printf("Error: sched_getaffinity(%d, sizeof(was_mask),&lt;BR /&gt;
	&amp;amp;was_mask)\n", ompTid);&lt;BR /&gt;
	}&lt;BR /&gt;
	if (sched_setaffinity(0, sizeof(new_mask), &amp;amp;new_mask)&lt;BR /&gt;
	== -1) {printf("Error: sched_setaffinity(%d, sizeof(new_mask),&lt;BR /&gt;
	&amp;amp;new_mask)\n", ompTid);&lt;BR /&gt;
	}&lt;BR /&gt;
	printf("tid=%d new_mask=%08X was_mask=%08X\n", ompTid,&lt;BR /&gt;
	*(unsigned int*)(&amp;amp;new_mask), *(unsigned int*)(&amp;amp;was_mask));&lt;BR /&gt;
	}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;BR style=" font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; " /&gt;
	Thanks&lt;BR /&gt;
	​Ying&lt;/P&gt;</description>
      <pubDate>Mon, 18 Dec 2017 02:15:44 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/kmp-set-affinity-4-new-omp-mask-return-error-22/m-p/1173096#M8022</guid>
      <dc:creator>Ying_H_Intel</dc:creator>
      <dc:date>2017-12-18T02:15:44Z</dc:date>
    </item>
    <item>
      <title>The 2nd argument to shed</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/kmp-set-affinity-4-new-omp-mask-return-error-22/m-p/1173097#M8023</link>
      <description>&lt;P&gt;The 2nd argument to shed_setaffinity and sched_getaffinity is the cpusetsize (IOW number of valid&amp;nbsp;bits in the mask). You are passing sizeof(cpu_set_t) which is the number of bytes in the mask. Note, you cannot use number of bytes * 8 as the valid bit field will be .LE. that number of bits.&lt;/P&gt;

&lt;P&gt;Also note, depending on your O/S build, the header bytesize for cpu_set_t could potentially be incorrect. The default number of bits is 1024, your system values may vary from this.&lt;/P&gt;

&lt;P&gt;See: &lt;A href="https://linux.die.net/man/3/cpu_set"&gt;https://linux.die.net/man/3/cpu_set&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Mon, 18 Dec 2017 17:32:08 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/kmp-set-affinity-4-new-omp-mask-return-error-22/m-p/1173097#M8023</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2017-12-18T17:32:08Z</dc:date>
    </item>
  </channel>
</rss>

