Exemple #1
0
static void * thr_fn0(void *arg)
{
	printids("new thread0: ");
	char input_buf1[INPUT_LEN];
	char input_buf2[INPUT_LEN];
	int i;
	int str_len;
	int sent;
	comm_create(device1, nblks, blksz);
	comm_create(device2, nblks, blksz);

	/*read input from standard I/O, one line at a time, input_buf2 reverses input_buf1.*/
	while(NULL != fgets(input_buf1, INPUT_LEN-1, stdin))
	{
		str_len = strlen(input_buf1);
		input_buf1[str_len - 1] = '\0';
		str_len = strlen(input_buf1);
		for(i = 0; i < str_len; ++i)
		{
			input_buf2[i] = input_buf1[str_len-1-i];
		}
		input_buf2[i] = '\0';
		comm_info("Thread0 send input1:%s, length is:%d\n", input_buf1, str_len);
		sent = comm_send(device1, input_buf1, str_len);
		comm_info("Thread0 sent length is:%d\n", sent);

		comm_info("Thread0 send input2:%s, length is:%d\n", input_buf2, str_len);
		sent = comm_send(device2, input_buf2, str_len);
		comm_info("Thread0 sent length is:%d\n", sent);
	}
}
Exemple #2
0
 TreeCommunicator::TreeCommunicator(const std::vector<int> &fan_out, GlobalPolicy *global_policy, const MPI_Comm &comm)
     : m_fan_out(fan_out)
     , m_comm(fan_out.size())
     , m_global_policy(global_policy)
     , m_level(fan_out.size())
 {
     mpi_type_create();
     comm_create(comm);
     level_create();
 }
Exemple #3
0
static int single_thread_test()
{
    char send_str[] = "send data";
    int send_count = sizeof(send_str);
	int sent = 0;
    char recv_str[10] = {'\0',};
    int rcv_len;
	int received = 0;
	int device = 0;/*which device [0,31]*/
	int times = 1;
    comm_initialize(device,COMM_NBLOCK);

#if 1
/*XXX test create*/
    comm_info("Test create start.\n");
	comm_create(device, nblks, blksz);
    comm_info("Test create end.\n");
#endif

#if 1
/*XXX test send and receive one time.*/
    comm_info("Test send start.\n");
    comm_info("Send data is:%s\n",send_str);
	sent = comm_send(device, send_str, send_count);
    comm_info("Sent length is:%d\n",sent);

    comm_info("Test receive start.\n");
	do
	{
		rcv_len = comm_getlen(device);
	}while(rcv_len < 0);
	comm_receive(device, recv_str, rcv_len);
    comm_info("Received data is:%s\n",recv_str);
    comm_info("Received length is:%d\n",rcv_len);
#endif

#if 1
/*XXX test send and receive many times*/
	while(times<6)
	{
		comm_info("times:%d.\n",times);
		send_str[0]+=1;
		times +=1;
		comm_info("Test send start.\n");
		comm_info("Send data is:%s\n",send_str);
		sent = comm_send(device, send_str, send_count);
		comm_info("Sent length is:%d\n",sent);

		comm_info("Test receive start.\n");
		do
		{
			rcv_len = comm_getlen(device);
		}while(rcv_len < 0);
		comm_receive(device, recv_str, rcv_len);
		comm_info("Received data is:%s\n",recv_str);
		comm_info("Received length is:%d\n",rcv_len);
	}
#endif

    comm_release(device);
	comm_info("Test end.\n");
}
Exemple #4
0
struct conn *
conn_new(struct fde_head *h, struct cfg *cfg, struct shm_alloc_state *sm,
    int fd, conn_owner_update_cb *cb, void *cbdata)
{
	struct conn *c;
	char *buf;
	int i;
	int sn;

	c = calloc(1, sizeof(*c));
	if (c == NULL) {
		warn("%s: calloc", __func__);
		return (NULL);
	}

	c->r.size = cfg->io_size;
	c->r.buf = malloc(c->r.size);
	if (c->r.buf == NULL) {
		warn("%s: malloc", __func__);
		free(c);
		return (NULL);
	}

	c->w.nb = iapp_netbuf_alloc(sm, cfg->atype, cfg->io_size);
	if (c->w.nb == NULL) {
		warn("%s: iapp_netbuf_alloc", __func__);
		free(c->r.buf);
		free(c);
		return (NULL);
	}

	/* Pre-populate with some data */
	buf = iapp_netbuf_buf_nonconst(c->w.nb);
	for (i = 0; i < iapp_netbuf_size(c->w.nb); i++) {
		buf[i] = (i % 10) + '0';
	}

	/*
	 * Limit the send size to one buffer for now.
	 *
	 * This isn't optimal but until we queue multiple buffers
	 * via sendfile, we will end up queueing the same memory region
	 * over and over again via different mbufs to the same socket
	 * and that isn't at all useful or correct.
	 *
	 * Once the shm allocator handles returning buffers, we can
	 * modify the transmit path to allocate buffers as required and
	 * then keep up to two in flight.  Then we can just remove
	 * this limit.
	 */
	sn = cfg->io_size;
	if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &sn, sizeof(sn)) < 0)
		warn("%s: setsockopt(SO_SNDBUF)", __func__);

	c->fd = fd;
	c->comm = comm_create(fd, h, client_ev_close_cb, c);
	c->ev_cleanup = fde_create(h, -1, FDE_T_CALLBACK, 0,
	    client_ev_cleanup_cb, c);
	c->state = CONN_STATE_RUNNING;

	/* Link back to the parent fde loop */
	c->h = h;

	/* .. and the callback state for notification */
	c->cb.cb = cb;
	c->cb.cbdata = cbdata;

#if 0
	/*
	 * Start reading!
	 */
	(void) comm_read(c->comm, c->r.buf, c->r.size, client_read_cb, c);
#endif

	/*
	 * Start writing!
	 */
	comm_write(c->comm, c->w.nb, 0, iapp_netbuf_size(c->w.nb), conn_write_cb, c);

	return (c);
}