<?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 Multi-threading with Intel MPI in Intel® MPI Library</title>
    <link>https://community.intel.com/t5/Intel-MPI-Library/Multi-threading-with-Intel-MPI/m-p/946124#M2839</link>
    <description>&lt;P&gt;I am trying to establish communication between threads on different processes using Intel MPI.&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="line-height: 1.5; font-size: 1em;"&gt;However, it does not seem to work as I would expect it to.&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;Here's the code snippet:&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;MPI_Comm_dup(MPI_COMM_WORLD, &amp;amp;dup_world_comm0);&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;MPI_Comm_group(dup_world_comm0, &amp;amp;world_group0);&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;MPI_Comm_create(dup_world_comm0, world_group0, &amp;amp;world_comm0);&lt;SPAN style="line-height: 1.5; font-size: 1em;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="line-height: 1.5; font-size: 1em;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;/*inside a thread*/&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (myrank == 0) {//process 0&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; i = find_sum();&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (index == 0) {//thread id 0&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; MPI_Send(&amp;amp;i, 1, MPI_INT, 1, 1, world_comm0);&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; MPI_Recv(&amp;amp;y, 1, MPI_INT, 1, 1, world_comm0, &amp;amp;status);&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (myrank == 1) {//process 1&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (index == 0) {//thread id 0&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; MPI_Recv(&amp;amp;i, 1, MPI_INT, 0, 1, world_comm0, &amp;amp;status);&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; MPI_Send(&amp;amp;i, 1, MPI_INT, 0, 1, world_comm0);&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/P&gt;

&lt;P&gt;------------------------------------&lt;/P&gt;

&lt;P&gt;I am spawning a single thread on each process and am trying to establish some communication between these threads using MPI_Send/Recv.&lt;/P&gt;

&lt;P&gt;But, many a times, the execution hangs on MPI_Recv or MPI_Send in process 1.&lt;/P&gt;

&lt;P&gt;Is their something that I am missing here or doing wrong &amp;nbsp;or is the library not supposed to work in this way with threads?&lt;/P&gt;

&lt;P&gt;I have attached the code file for reference.&lt;/P&gt;

&lt;P&gt;Thanks.&lt;/P&gt;</description>
    <pubDate>Thu, 26 Dec 2013 16:01:28 GMT</pubDate>
    <dc:creator>Kunal_M_</dc:creator>
    <dc:date>2013-12-26T16:01:28Z</dc:date>
    <item>
      <title>Multi-threading with Intel MPI</title>
      <link>https://community.intel.com/t5/Intel-MPI-Library/Multi-threading-with-Intel-MPI/m-p/946124#M2839</link>
      <description>&lt;P&gt;I am trying to establish communication between threads on different processes using Intel MPI.&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="line-height: 1.5; font-size: 1em;"&gt;However, it does not seem to work as I would expect it to.&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;Here's the code snippet:&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;MPI_Comm_dup(MPI_COMM_WORLD, &amp;amp;dup_world_comm0);&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;MPI_Comm_group(dup_world_comm0, &amp;amp;world_group0);&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;MPI_Comm_create(dup_world_comm0, world_group0, &amp;amp;world_comm0);&lt;SPAN style="line-height: 1.5; font-size: 1em;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="line-height: 1.5; font-size: 1em;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;/*inside a thread*/&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (myrank == 0) {//process 0&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; i = find_sum();&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (index == 0) {//thread id 0&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; MPI_Send(&amp;amp;i, 1, MPI_INT, 1, 1, world_comm0);&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; MPI_Recv(&amp;amp;y, 1, MPI_INT, 1, 1, world_comm0, &amp;amp;status);&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (myrank == 1) {//process 1&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (index == 0) {//thread id 0&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; MPI_Recv(&amp;amp;i, 1, MPI_INT, 0, 1, world_comm0, &amp;amp;status);&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; MPI_Send(&amp;amp;i, 1, MPI_INT, 0, 1, world_comm0);&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/P&gt;

&lt;P&gt;------------------------------------&lt;/P&gt;

&lt;P&gt;I am spawning a single thread on each process and am trying to establish some communication between these threads using MPI_Send/Recv.&lt;/P&gt;

&lt;P&gt;But, many a times, the execution hangs on MPI_Recv or MPI_Send in process 1.&lt;/P&gt;

&lt;P&gt;Is their something that I am missing here or doing wrong &amp;nbsp;or is the library not supposed to work in this way with threads?&lt;/P&gt;

&lt;P&gt;I have attached the code file for reference.&lt;/P&gt;

&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Dec 2013 16:01:28 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-MPI-Library/Multi-threading-with-Intel-MPI/m-p/946124#M2839</guid>
      <dc:creator>Kunal_M_</dc:creator>
      <dc:date>2013-12-26T16:01:28Z</dc:date>
    </item>
    <item>
      <title>Hi Kunal,</title>
      <link>https://community.intel.com/t5/Intel-MPI-Library/Multi-threading-with-Intel-MPI/m-p/946125#M2840</link>
      <description>&lt;P&gt;Hi Kunal,&lt;/P&gt;

&lt;P&gt;I am able to run your code with only one modification (not related to this, see below).&amp;nbsp; How are you compiling?&amp;nbsp; Did you remember to link to the multithreaded MPI library?&amp;nbsp; I compiled with:&lt;/P&gt;

&lt;P&gt;[plain]mpiicpc test_MPI_thread.cpp -mt_mpi[/plain]&lt;/P&gt;

&lt;P&gt;Using the Intel® C++ Compiler 2013 Update 5.&lt;/P&gt;

&lt;P&gt;Your code appears fine, but I do have&amp;nbsp;a few recommendations.&amp;nbsp; When you are creating the communicators (lines 208 through 213), the world_comm0 and world_comm1 communicators you are creating are identical to the dup_world_comm0 and dup_world_comm1 communicators you previously created.&amp;nbsp; These are at all points after creation identical to MPI_COMM_WORLD.&amp;nbsp; Unless you have future plans for them, you could simplify to just using MPI_COMM_WORLD.&lt;/P&gt;

&lt;P&gt;The modification I had to make was to remove the MPI_Recv on line 221.&amp;nbsp; If you are launching this spawned from a different MPI program, this is fine.&amp;nbsp; But as a standalone code, this doesn't work, as parentcomm is null.&amp;nbsp; I usually put an if (parentcomm!=MPI_COMM_NULL) block to protect calls like this.&lt;/P&gt;

&lt;P&gt;Sincerely,&lt;BR /&gt;
	James Tullos&lt;BR /&gt;
	Technical Consulting Engineer&lt;BR /&gt;
	Intel® Cluster Tools&lt;/P&gt;</description>
      <pubDate>Tue, 31 Dec 2013 16:51:35 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-MPI-Library/Multi-threading-with-Intel-MPI/m-p/946125#M2840</guid>
      <dc:creator>James_T_Intel</dc:creator>
      <dc:date>2013-12-31T16:51:35Z</dc:date>
    </item>
  </channel>
</rss>

