Passing a struct with GM

"Florian Brulhart" <[email protected]> Tue, 17 Oct 2006 11:21:28 -0600
Newsgroups gmane.network.myrinet.general
Message-ID <[email protected]>
--===============0884312319==
Content-Type: multipart/alternative; 
	boundary="----=_Part_80093_19139582.1161105688411"

------=_Part_80093_19139582.1161105688411
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hello guys,

We are two student who work on a Sent/Receive on a Myrinet Network.
We try to send a "struct" with GM between two nodes. The send work and we
can got the message on the receiver part, but we cannot read the information
of our message. I will try to explain that with our source code.

This struct is :

struct gm_msg{
   int idConn;
   char * data;
}

somewhere in our code, we create another struct gm_connect_msg { int nodeID
int portID;} and we send them with this method :
-----------------------------------------------------------------------------------------------------------------------
...
gm_connect_msg msg_connect;
msg_connect.nodeID = 1;
msg_connect.portID = 2;
Send(&msg_connect,sizeof(msg_connect));
...

int paroc_combox_gm::Send(const char *m, int len){
printf("[DEBUG]Init of Send(char*, int)\n");
  gm_recv_event_t *event;
  void *sendBuffer=NULL;
  int expected_callbacks=0;
  gm_status_t status;
  gm_msg msg;
  int length;
  printf("[DEBUG] variables sets, begin memcpy\n");
  gm_printf("[DEBUG] m param :%s, his lenght : %i \n",m,len);
  msg.data = (char *)malloc(len);
  memcpy(msg.data,m,len);
  printf("[DEBUG] end of memcpy \n");
  msg.idConn = idConn;
  length = sizeof(msg);
  /* Buffers are preallocated to CACTUS_MSG_SIZE other buffers need to be
handled */
  nNextSendBuffer = (nNextSendBuffer + 1) % nSendTokens;

  printf("[DEBUG] End of init of send \n");
  gm_printf("[DEBUG] find a free buffer and send Token\n");

  if(gm_send_buffer[nNextSendBuffer].state != BUFFER_FREE){
    while(nNextSendBuffer < nSendTokens){
      nNextSendBuffer=(nNextSendBuffer+1) % nSendTokens;
      if(gm_send_buffer[nNextSendBuffer].state == BUFFER_FREE)
        break;
      }
      if(nNextSendBuffer==nSendTokens &&
gm_send_buffer[nNextSendBuffer].state==BUFFER_IN_USE){
        fprintf(stdout,"Not enough Tokens for send \n");
        return -1;
      }
  }
  printf("[DEBUG] free buffer ok!\n");

  sendBuffer=gm_send_buffer[nNextSendBuffer].data;
  printf("Len: %i\n", strlen(msg.data)+1);

  gm_printf("[DEBUG] registration of the message in buffer \n");
  memcpy(gm_send_buffer[nNextSendBuffer].data,&msg,length);

  gm_printf("DESTINATION : Node=%i ;Port=%i", destNodeID, destPortID);

  gm_send_with_callback(gm_port,sendBuffer,
                  gm_log2_roundup(MSG_SIZE),
                  length,GM_LOW_PRIORITY,
                  destNodeID,destPortID,
                  send_callback,
                  &gm_send_buffer[nNextSendBuffer]);

    fprintf(stdout,"Send-Msg Sent Message successfully\n");
    while (1){
      event = gm_receive (gm_port);
      switch (GM_RECV_EVENT_TYPE(event))
      {
        case GM_RECV_EVENT:
        case GM_PEER_RECV_EVENT:
        case GM_FAST_PEER_RECV_EVENT:
          gm_printf ("[send] Receive Event (UNEXPECTED)\n");
          status = GM_FAILURE; /* Unexpected incoming message */
          return -1;

        case GM_NO_RECV_EVENT:
         break;

        default:
         gm_unknown (gm_port, event);    /* gm_unknown calls the callback */
         return 0;
      }
    }
  return (GM_SUCCESS);
}
-----------------------------------------------------------------------------------------------------------------------

And our Receive function is :
-----------------------------------------------------------------------------------------------------------------------
int paroc_combox_gm::Recv(char * msg, int msgLength){
  printf("Recv() in Combox_gm\n");
  gm_recv_event_t *event;
  void *buffer;
  unsigned int size;
  int messages_expected = 1;
  unsigned int len;
  void * message;
  gm_msg m;


  gm_connect_msg tmpmsg;
  gm_connect_msg * tmpptr;

  printf("\t Init passed\n");

  while(messages_expected > 0){
    event = gm_receive (gm_port);
    //      fprintf(stdout,"Received an Event \n");
    switch (GM_RECV_EVENT_TYPE(event)){
    case GM_RECV_EVENT:
    case GM_PEER_RECV_EVENT:
    case GM_FAST_PEER_RECV_EVENT:
      printf("\tyou have a new message\n");
      len=gm_ntoh_u32(event->recv.length);

      memcpy(&m, gm_ntohp(event->recv.message), len);


      printf("\tm init\n");
      printf("idConn = %i\n",m.idConn);

      printf("\t tmp init\n");
      tmpptr = (gm_connect_msg *) m.data;
      printf("\tmsg copy done\n");
      printf("\tm.data : %s\n",m.data);
      printf("\tm.idConn : %d\n",m.idConn); //this is right
      printf("\ttmpptr.node : %d",tmpptr->nodeID);//this is wrong

      messages_expected--;
      /* Return the buffer for reuse */
      buffer = gm_ntohp (event->recv.buffer);
      size = (unsigned int)gm_ntoh_u8 (event->recv.size);
      gm_provide_receive_buffer (gm_port, buffer, gm_log2_roundup(MSG_SIZE),
                                 GM_LOW_PRIORITY);
      printf("\trecv buffer re-provided\n");
      break;

    case GM_NO_RECV_EVENT:
      break;

    default:
      gm_unknown (gm_port, event);      /* gm_unknown calls the callback */
    }
  }
}
-----------------------------------------------------------------------------------------------------------------------



but unfortunately, when the message arrive, we have some magic number for
the nodeID and the portID like "1406914151".

Have you any idea ?


Thanks for all..


Florian Brulhart & Stephane Droz

------=_Part_80093_19139582.1161105688411
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hello guys,<br><br>We are two student who work on a Sent/Receive on a Myrinet Network. <br>We try to send a &quot;struct&quot; with GM between two nodes. The send work and we can got the message on the receiver part, but we cannot read the information of our message. I will try to explain that with our source code.
<br><br>This struct is :<br><br>struct gm_msg{<br>&nbsp;&nbsp; int idConn;<br>&nbsp;&nbsp; char * data;<br>}<br><br>somewhere in our code, we create another struct gm_connect_msg { int nodeID int portID;} and we send them with this method :<br>
-----------------------------------------------------------------------------------------------------------------------<br>...<br>gm_connect_msg msg_connect;<br>msg_connect.nodeID = 1;<br>msg_connect.portID = 2;<br>Send(&amp;msg_connect,sizeof(msg_connect));
<br>...<br><br>int paroc_combox_gm::Send(const char *m, int len){<br>printf(&quot;[DEBUG]Init of Send(char*, int)\n&quot;);<br>&nbsp; gm_recv_event_t *event;<br>&nbsp; void *sendBuffer=NULL;<br>&nbsp; int expected_callbacks=0;<br>&nbsp; gm_status_t status;
<br>&nbsp; gm_msg msg;<br>&nbsp; int length;<br>&nbsp; printf(&quot;[DEBUG] variables sets, begin memcpy\n&quot;);<br>&nbsp; gm_printf(&quot;[DEBUG] m param :%s, his lenght : %i \n&quot;,m,len);<br>&nbsp; <span style="font-weight: bold;">msg.data
 = (char *)malloc(len);</span><br style="font-weight: bold;"><span style="font-weight: bold;">&nbsp; memcpy(msg.data,m,len);</span><br>&nbsp; printf(&quot;[DEBUG] end of memcpy \n&quot;);<br>&nbsp; msg.idConn = idConn;<br>&nbsp; length = sizeof(msg);
<br>&nbsp; /* Buffers are preallocated to CACTUS_MSG_SIZE other buffers need to be handled */<br>&nbsp; nNextSendBuffer = (nNextSendBuffer + 1) % nSendTokens;<br><br>&nbsp; printf(&quot;[DEBUG] End of init of send \n&quot;);<br>&nbsp; gm_printf(&quot;[DEBUG] find a free buffer and send Token\n&quot;);
<br><br>&nbsp; if(gm_send_buffer[nNextSendBuffer].state != BUFFER_FREE){<br>&nbsp;&nbsp;&nbsp; while(nNextSendBuffer &lt; nSendTokens){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nNextSendBuffer=(nNextSendBuffer+1) % nSendTokens;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(gm_send_buffer[nNextSendBuffer].state == BUFFER_FREE)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(nNextSendBuffer==nSendTokens &amp;&amp; gm_send_buffer[nNextSendBuffer].state==BUFFER_IN_USE){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fprintf(stdout,&quot;Not enough Tokens for send \n&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return -1;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp; }<br>&nbsp; printf(&quot;[DEBUG] free buffer ok!\n&quot;);<br><br>&nbsp; sendBuffer=gm_send_buffer[nNextSendBuffer].data;<br>&nbsp; printf(&quot;Len: %i\n&quot;, strlen(msg.data)+1);<br><br>&nbsp; gm_printf(&quot;[DEBUG] registration of the message in buffer \n&quot;);
<br>&nbsp; <span style="font-weight: bold;">memcpy(gm_send_buffer[nNextSendBuffer].data,&amp;msg,length);</span><br><br>&nbsp; gm_printf(&quot;DESTINATION : Node=%i ;Port=%i&quot;, destNodeID, destPortID);<br><br>&nbsp; gm_send_with_callback(gm_port,sendBuffer,
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gm_log2_roundup(MSG_SIZE),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; length,GM_LOW_PRIORITY,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; destNodeID,destPortID,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-weight: bold;">send_callback</span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &amp;gm_send_buffer[nNextSendBuffer]);
<br><br>&nbsp;&nbsp;&nbsp; fprintf(stdout,&quot;Send-Msg Sent Message successfully\n&quot;);<br>&nbsp;&nbsp;&nbsp; while (1){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; event = gm_receive (gm_port);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; switch (GM_RECV_EVENT_TYPE(event))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case GM_RECV_EVENT:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case GM_PEER_RECV_EVENT:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case GM_FAST_PEER_RECV_EVENT:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gm_printf (&quot;[send] Receive Event (UNEXPECTED)\n&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; status = GM_FAILURE; /* Unexpected incoming message */<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return -1;
<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case GM_NO_RECV_EVENT:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; default:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gm_unknown (gm_port, event);&nbsp;&nbsp;&nbsp; /* gm_unknown calls the callback */<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp; return (GM_SUCCESS);
<br>}<br>-----------------------------------------------------------------------------------------------------------------------<br><br>
And our Receive function is :<br>-----------------------------------------------------------------------------------------------------------------------<br>int paroc_combox_gm::Recv(char * msg, int msgLength){<br>&nbsp; printf(&quot;Recv() in Combox_gm\n&quot;);
<br>&nbsp; gm_recv_event_t *event;<br>&nbsp; void *buffer;<br>&nbsp; unsigned int size;<br>&nbsp; int messages_expected = 1;<br>&nbsp; unsigned int len;<br>&nbsp; void * message;<br>&nbsp; <span style="font-weight: bold;">gm_msg m;</span><br><br><br>&nbsp; gm_connect_msg tmpmsg;
<br>&nbsp; gm_connect_msg * tmpptr;<br><br>&nbsp; printf(&quot;\t Init passed\n&quot;);<br><br>&nbsp; while(messages_expected &gt; 0){<br>&nbsp;&nbsp;&nbsp; event = gm_receive (gm_port);<br>&nbsp;&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fprintf(stdout,&quot;Received an Event \n&quot;);
<br>&nbsp;&nbsp;&nbsp; switch (GM_RECV_EVENT_TYPE(event)){<br>&nbsp;&nbsp;&nbsp; case GM_RECV_EVENT:<br>&nbsp;&nbsp;&nbsp; case GM_PEER_RECV_EVENT:<br>&nbsp;&nbsp;&nbsp; case GM_FAST_PEER_RECV_EVENT:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(&quot;\tyou have a new message\n&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; len=gm_ntoh_u32(event-&gt;
recv.length);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-weight: bold;">memcpy(&amp;m, gm_ntohp(event-&gt;recv.message), len);</span><br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(&quot;\tm init\n&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(&quot;idConn = %i\n&quot;,m.idConn
);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(&quot;\t tmp init\n&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-weight: bold;">tmpptr = (gm_connect_msg *) m.data;</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(&quot;\tmsg copy done\n&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(&quot;\tm.data : %s\n&quot;,
m.data);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(&quot;\tm.idConn : %d\n&quot;,m.idConn); //<span style="font-weight: bold;">this is right</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(&quot;\ttmpptr.node : %d&quot;,tmpptr-&gt;nodeID);/<span style="font-weight: bold;">
/this is wrong</span><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; messages_expected--;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* Return the buffer for reuse */<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; buffer = gm_ntohp (event-&gt;recv.buffer);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; size = (unsigned int)gm_ntoh_u8 (event-&gt;recv.size);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gm_provide_receive_buffer (gm_port, buffer, gm_log2_roundup(MSG_SIZE),
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GM_LOW_PRIORITY);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(&quot;\trecv buffer re-provided\n&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br><br>&nbsp;&nbsp;&nbsp; case GM_NO_RECV_EVENT:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br><br>&nbsp;&nbsp;&nbsp; default:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gm_unknown (gm_port, event);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* gm_unknown calls the callback */
<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp; }<br>}<br>-----------------------------------------------------------------------------------------------------------------------<br><br><br><br>but unfortunately, when the message arrive, we have some magic number for the nodeID and the portID like &quot;1406914151&quot;.
<br><br>Have you any idea ?<br><br><br>Thanks for all..<br><br><br>Florian Brulhart &amp; Stephane Droz<br><br><br><br><br><br><br><br><br><br><br><br>

------=_Part_80093_19139582.1161105688411--

--===============0884312319==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Myrinet mailing list
[email protected]
http://email.osc.edu/mailman/listinfo/myrinet
--===============0884312319==--