[Myrinet] exchange info with gm

"TOUCHE Julien" <[email protected]>
Newsgroups gmane.network.myrinet.general
Organization Lycos Mail (http://www.mail.lycos.com:80)
Message-ID <[email protected]>
Hello

it try to make "simple" functions to exchange between my hosts,
their id, directed address, but i encounter some problems: SIGSEGV for sprintf, or gm_free and i don't obtain the same 
info on my remote host ...

some help would be appreciate.
many parts of the code are from gm simple example.

---

Thanks
bye

           Julien Touche
-----------------------------------------------------------
extract of the code

#define DIRECTED_SEND(buffer) /* globals var */\
  gm_directed_send_with_callback (my_port, \
	&buffer,\
	(gm_remote_ptr_t) (remote_directed_addr),\
	(unsigned long) sizeof (buffer) + 1,\
	 GM_SIMPLE_EXAMPLE_PRIORITY,\
	 remote_node_id,\
	 GM_SIMPLE_EXAMPLE_PORT_NUM,\
	 NULL,NULL);

void allocate_gm(gmtype* buffer, struct gm_port *port, int count, int length)
{
	if (*buffer==NULL)
	{
		*buffer = gm_dma_calloc (port, count, length);
		if (*buffer == 0)
	    {
			gm_printf ("%s : Couldn't allocate buffer\n", __FILE__);
			main_status = GM_OUT_OF_MEMORY;
	    }
	}
	else
	{
		gm_register_memory(port, *buffer, sizeof(*buffer));
	}
}

void allocate_gm_char(char** buffer, struct gm_port *port, int count, int length)
{
	if (*buffer==NULL)
	{
		*buffer = gm_dma_calloc (port, count, length);
		if (*buffer == 0)
	    {
			gm_printf ("%s : Couldn't allocate buffer\n", __FILE__);
			main_status = GM_OUT_OF_MEMORY;
	    }
	}
	else
	{
		gm_register_memory(port, *buffer, sizeof(*buffer));
	}
	*buffer = "\0";
//  printf("allocate: buf: %p\n",*buffer);
}


void unallocate_gm(gmtype* buffer)
{
	if (buffer != 0 && *buffer != 0)
		gm_free(*buffer);
}

void unallocate_gm_char(char** buffer)
{
	if (buffer != 0 && *buffer!=0)
		gm_free(*buffer);
}

/* exchange node_id & dma address for receiving on port : */
/* use out_buffer of local_node_id on port to send to */
/* node_id: local_node_id and directed_addr */
int send_gm_info(struct gm_port *port,
	unsigned int node_id, unsigned int local_node_id,
	gm_remote_ptr_t directed_addr)
{
  char* out_buffer;
  gm_se_context_t context;
  context.messages_expected = 0;
  context.callbacks_pending = 0;

  printf("send: remote node %d, remote address %p\n", 
  		local_node_id, directed_addr);
  
  allocate_gm_char(&out_buffer, port,  GM_SIMPLE_EXAMPLE_BUFFER_COUNT,
		GM_SIMPLE_EXAMPLE_BUFFER_LENGTH);

PINFO()
//  sprintf (out_buffer, "%d", my_node_id);
//sprintf (out_buffer, "%1d\0", local_node_id);  
//	out_buffer[0] = (char)local_node_id;
out_buffer = "1";
PINFO()
//  out_buffer = (gmtype)local_node_id;
  printf("%s\n",out_buffer);
  gm_send_to_peer_with_callback (port,
				 out_buffer,
				 GM_SIMPLE_EXAMPLE_SIZE,
				 (unsigned int) sizeof (out_buffer) + 1,
				 GM_SIMPLE_EXAMPLE_PRIORITY,
 				 node_id,
				 my_send_callback,
				 &context);
  context.callbacks_pending++;
PINFO()
  wait_for_events (port, &context); /* For simplicity, wait for callback
					  before going on */
PINFO()
//  sprintf (out_buffer, "%p\0", directed_addr);
  out_buffer = (gmtype)directed_addr;
  printf("buf %s / %p\n",out_buffer,out_buffer);
  gm_send_to_peer_with_callback (port,
				 out_buffer,
				 GM_SIMPLE_EXAMPLE_SIZE,
				 (unsigned long) sizeof (out_buffer) + 1,
				 GM_SIMPLE_EXAMPLE_PRIORITY,
				 node_id,
				 my_send_callback,
				 &context);
  context.callbacks_pending++;
PINFO()

  unallocate_gm_char(&out_buffer);

  printf("send: remote node %d, remote address %p\n", local_node_id, directed_addr);
 
  return 0;
}
	
int recv_gm_info(struct gm_port *port,
	unsigned int node_id, gm_remote_ptr_t directed_addr)
{
  gm_recv_event_t *event;
  gm_status_t main_status;
  int expected_messages = 2;
  char receiver_node_id_c[9], directed_send_addr_c[17];
  char* in_buffer;

  allocate_gm_char(&in_buffer, port,  GM_SIMPLE_EXAMPLE_BUFFER_COUNT,
		GM_SIMPLE_EXAMPLE_BUFFER_LENGTH);

  /* Tell GM where our receive buffer is */
PINFO()
  gm_provide_receive_buffer (port, in_buffer, GM_SIMPLE_EXAMPLE_SIZE,
			     GM_SIMPLE_EXAMPLE_PRIORITY);
  
  /* Wait for the two messages from gm_simple_example_recv */

  while (expected_messages)
    {
      void *buffer;
      unsigned int size;

      event = gm_receive (port);

      switch (gm_ntoh_u8 (event->recv.type))
	{
	case GM_RECV_EVENT:
	case GM_PEER_RECV_EVENT:
	case GM_FAST_PEER_RECV_EVENT:
PINFO()
	  if (expected_messages == 2)
	    {			/* 1st message carries node_id */
	      if (gm_ntoh_u32 (event->recv.length) >=
		  sizeof (receiver_node_id_c))
		{
		  gm_printf ("%s *** ERROR: incoming message length %d "
			     "exceeds maximum of %ld\n", __FILE__,
			     gm_ntoh_u32 (event->recv.length),
			     (long int)(sizeof (receiver_node_id_c) - 1));
		  main_status = GM_FAILURE; /* Unexpected incoming message */
		  end();
		}

	      gm_strncpy (receiver_node_id_c,
			  (char *) gm_ntohp (event->recv.message),
			  sizeof (receiver_node_id_c) - 1);
		  printf("id %d / %s / %p\n",receiver_node_id_c,receiver_node_id_c, receiver_node_id_c);
	      sscanf (receiver_node_id_c, "%d", &node_id);
	    }
	  else
	    {			/* 2nd message carries address */
	      if (gm_ntoh_u32 (event->recv.length) >=
		  sizeof (directed_send_addr_c))
		{
		  gm_printf ("*** ERROR: incoming message length %d "
			     "exceeds maximum of %ld\n",
			     gm_ntoh_u32 (event->recv.length),
			     (long int)(sizeof (directed_send_addr_c) -1));
		  main_status = GM_FAILURE; /* Unexpected incoming message */
	      end();
		}

	      gm_strncpy (directed_send_addr_c,
			  (char *) gm_ntohp (event->recv.message),
			  (long int)(sizeof (directed_send_addr_c) -1));
		  printf("buf %s / %p\n",directed_send_addr_c,directed_send_addr_c);
	      sscanf (directed_send_addr_c, "%p",
		      (void **)&directed_addr);
	    }

	  expected_messages--;

	  /* Return the buffer for reuse */

	  buffer = gm_ntohp (event->recv.buffer);
	  size = gm_ntoh_u8 (event->recv.size);
	  gm_provide_receive_buffer (port, in_buffer, size, 
				     GM_SIMPLE_EXAMPLE_PRIORITY);
	  break;

	case GM_NO_RECV_EVENT:
	  break;

	default:
	  gm_unknown (port, event);	/* gm_unknown calls the callback */
	}
    }
PINFO()

  	unallocate_gm_char(&in_buffer);
  
	printf("recv: remote node %d, remote address %p\n", node_id, directed_addr);
	return 0;
}




and at the end
send:

recv_gm_info(my_port, remote_node_id, remote_directed_addr);


recv:


recv_gm_info(my_port, my_node_id, remote_directed_addr);








_________________________________________
Communicate with others using Lycos Mail for FREE!
<a href=http://mail.lycos.com/>http://mail.lycos.com/</a>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.