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