dart/gni/ds_base_gni.c
struct dart_server *ds_alloc(int num_sp, int num_cp, void *dart_ref, void *comm)
{
	struct dart_server *ds = 0;
	struct node_id *peer;
	struct node_id *peer_list;
	size_t size;
	int i, err;
	int node_size;

	size = sizeof(struct dart_server) + num_sp * sizeof(struct node_id);
	ds = calloc(1, size);
	if (!ds)
		goto err_out;
	ds->dart_ref = dart_ref;
	ds->peer_tab = (struct node_id *)(ds + 1);

	ds->peer_size = num_sp; //peer_size represents current number of peers in total

	ds->size_sp = num_sp;
	ds->num_sp = num_sp;

	INIT_LIST_HEAD(&ds->app_list);

	if(comm) {
		ds->comm = malloc(sizeof(*ds->comm));
		MPI_Comm_dup(*(MPI_Comm *)comm, ds->comm);
	} else {
		ds->comm = NULL;
	}

	ds->rpc_s = rpc_server_init(30, ds->peer_size, ds, DART_SERVER, 0, comm);
	if (!ds->rpc_s)
		goto err_free_dsrv;

	ds->rpc_s->app_num_peers = num_sp;
	ds->rpc_s->app_minid = 0;

	for (i=0; i < ds->size_sp; i++)
	{
		ds->peer_tab[i].ptlmap.nid = ds->rpc_s->peer_tab[i].ptlmap.nid;
		ds->peer_tab[i].ptlmap.pid = ds->rpc_s->peer_tab[i].ptlmap.pid;
		ds->peer_tab[i].ptlmap.id = ds->rpc_s->peer_tab[i].ptlmap.id;
		ds->peer_tab[i].ptlmap.appid = 0;
		ds->peer_tab[i].peer_rank = ds->rpc_s->peer_tab[i].ptlmap.id;
		ds->peer_tab[i].peer_num = ds->num_sp;
	}

	free(ds->rpc_s->peer_tab);
	ds->rpc_s->peer_tab = ds->peer_tab;

	peer = ds->peer_tab;
	for (i = 0; i < ds->size_sp; i++) ////DSaaS
	{
		INIT_LIST_HEAD(&peer->req_list);
		peer->num_msg_at_peer = ds->rpc_s->max_num_msg;

		peer->num_msg_recv = 0;
		peer->num_msg_ret = 0;	  

		peer->sys_msg_recv = 0;
		peer->sys_msg_at_peer = ds->rpc_s->max_num_msg;
		peer->sys_msg_ret = 0;	 
		peer->next = NULL;

		peer++;
	}

    rpc_add_service(cn_register, dsrpc_cn_register);
    rpc_add_service(cn_unregister, dsrpc_cn_unregister);
    rpc_add_service(sp_announce_cp, dsrpc_announce_cp);

	err = ds_boot(ds);
	if (err < 0)
		goto err_free_dsrv;

	if (num_sp == 1)
	{
		// If there is a single server, mark it as registered, but it should also be master!
		ds->f_reg = 1;
	}

	if(ds->comm) {
		err = MPI_Barrier(*ds->comm);
		assert(err == MPI_SUCCESS);
	} else {
		err = PMI_Barrier();	
		assert(err == PMI_SUCCESS);
	}

	uloga("'%s(%d)': init ok.\n", __func__, ds->self->ptlmap.id);

	return ds;

 err_free_dsrv:
	uloga("'%s()': failed with %d.\n", __func__, err);
	free(ds);
	return NULL;
 err_out:
	uloga("'%s()': failed with %d.\n", __func__, err);
	return NULL;
}
/* 
   Allocate and initialize dart server; the server initializes rpc
   server. 
*/
Allocate and initialize dart server; the server initializes rpc
server.
Allocate and initialize dart server ; the server initializes rpc server .
struct dart_server *ds_alloc(int num_sp, int num_cp, void *dart_ref, void *comm)
{
	struct dart_server *ds = 0;
	struct node_id *peer;
	struct node_id *peer_list;
	size_t size;
	int i, err;
	int node_size;
	size = sizeof(struct dart_server) + num_sp * sizeof(struct node_id);
	ds = calloc(1, size);
	if (!ds)
		goto err_out;
	ds->dart_ref = dart_ref;
	ds->peer_tab = (struct node_id *)(ds + 1);
	ds->peer_size = num_sp; 
	ds->size_sp = num_sp;
	ds->num_sp = num_sp;
	INIT_LIST_HEAD(&ds->app_list);
	if(comm) {
		ds->comm = malloc(sizeof(*ds->comm));
		MPI_Comm_dup(*(MPI_Comm *)comm, ds->comm);
	} else {
		ds->comm = NULL;
	}
	ds->rpc_s = rpc_server_init(30, ds->peer_size, ds, DART_SERVER, 0, comm);
	if (!ds->rpc_s)
		goto err_free_dsrv;
	ds->rpc_s->app_num_peers = num_sp;
	ds->rpc_s->app_minid = 0;
	for (i=0; i < ds->size_sp; i++)
	{
		ds->peer_tab[i].ptlmap.nid = ds->rpc_s->peer_tab[i].ptlmap.nid;
		ds->peer_tab[i].ptlmap.pid = ds->rpc_s->peer_tab[i].ptlmap.pid;
		ds->peer_tab[i].ptlmap.id = ds->rpc_s->peer_tab[i].ptlmap.id;
		ds->peer_tab[i].ptlmap.appid = 0;
		ds->peer_tab[i].peer_rank = ds->rpc_s->peer_tab[i].ptlmap.id;
		ds->peer_tab[i].peer_num = ds->num_sp;
	}
	free(ds->rpc_s->peer_tab);
	ds->rpc_s->peer_tab = ds->peer_tab;
	peer = ds->peer_tab;
	for (i = 0; i < ds->size_sp; i++) 
	{
		INIT_LIST_HEAD(&peer->req_list);
		peer->num_msg_at_peer = ds->rpc_s->max_num_msg;
		peer->num_msg_recv = 0;
		peer->num_msg_ret = 0;	  
		peer->sys_msg_recv = 0;
		peer->sys_msg_at_peer = ds->rpc_s->max_num_msg;
		peer->sys_msg_ret = 0;	 
		peer->next = NULL;
		peer++;
	}
    rpc_add_service(cn_register, dsrpc_cn_register);
    rpc_add_service(cn_unregister, dsrpc_cn_unregister);
    rpc_add_service(sp_announce_cp, dsrpc_announce_cp);
	err = ds_boot(ds);
	if (err < 0)
		goto err_free_dsrv;
	if (num_sp == 1)
	{
		ds->f_reg = 1;
	}
	if(ds->comm) {
		err = MPI_Barrier(*ds->comm);
		assert(err == MPI_SUCCESS);
	} else {
		err = PMI_Barrier();	
		assert(err == PMI_SUCCESS);
	}
	uloga("'%s(%d)': init ok.\n", __func__, ds->self->ptlmap.id);
	return ds;
 err_free_dsrv:
	uloga("'%s()': failed with %d.\n", __func__, err);
	free(ds);
	return NULL;
 err_out:
	uloga("'%s()': failed with %d.\n", __func__, err);
	return NULL;
}
struct dart_server * ds_alloc ( int num_sp , int num_cp , void * dart_ref , void * comm ) { struct dart_server * ds = 0 ; struct node_id * peer ; struct node_id * peer_list ; size_t size ; int i , err ; int node_size ; size = sizeof ( struct dart_server ) + num_sp * sizeof ( struct node_id ) ; ds = calloc ( 1 , size ) ; if ( ! ds ) goto err_out ; ds -> dart_ref = dart_ref ; ds -> peer_tab = ( struct node_id * ) ( ds + 1 ) ; ds -> peer_size = num_sp ; ds -> size_sp = num_sp ; ds -> num_sp = num_sp ; INIT_LIST_HEAD ( & ds -> app_list ) ; if ( comm ) { ds -> comm = malloc ( sizeof ( * ds -> comm ) ) ; MPI_Comm_dup ( * ( MPI_Comm * ) comm , ds -> comm ) ; } else { ds -> comm = NULL ; } ds -> rpc_s = rpc_server_init ( 30 , ds -> peer_size , ds , DART_SERVER , 0 , comm ) ; if ( ! ds -> rpc_s ) goto err_free_dsrv ; ds -> rpc_s -> app_num_peers = num_sp ; ds -> rpc_s -> app_minid = 0 ; for ( i = 0 ; i < ds -> size_sp ; i ++ ) { ds -> peer_tab [ i ] . ptlmap . nid = ds -> rpc_s -> peer_tab [ i ] . ptlmap . nid ; ds -> peer_tab [ i ] . ptlmap . pid = ds -> rpc_s -> peer_tab [ i ] . ptlmap . pid ; ds -> peer_tab [ i ] . ptlmap . id = ds -> rpc_s -> peer_tab [ i ] . ptlmap . id ; ds -> peer_tab [ i ] . ptlmap . appid = 0 ; ds -> peer_tab [ i ] . peer_rank = ds -> rpc_s -> peer_tab [ i ] . ptlmap . id ; ds -> peer_tab [ i ] . peer_num = ds -> num_sp ; } free ( ds -> rpc_s -> peer_tab ) ; ds -> rpc_s -> peer_tab = ds -> peer_tab ; peer = ds -> peer_tab ; for ( i = 0 ; i < ds -> size_sp ; i ++ ) { INIT_LIST_HEAD ( & peer -> req_list ) ; peer -> num_msg_at_peer = ds -> rpc_s -> max_num_msg ; peer -> num_msg_recv = 0 ; peer -> num_msg_ret = 0 ; peer -> sys_msg_recv = 0 ; peer -> sys_msg_at_peer = ds -> rpc_s -> max_num_msg ; peer -> sys_msg_ret = 0 ; peer -> next = NULL ; peer ++ ; } rpc_add_service ( cn_register , dsrpc_cn_register ) ; rpc_add_service ( cn_unregister , dsrpc_cn_unregister ) ; rpc_add_service ( sp_announce_cp , dsrpc_announce_cp ) ; err = ds_boot ( ds ) ; if ( err < 0 ) goto err_free_dsrv ; if ( num_sp == 1 ) { ds -> f_reg = 1 ; } if ( ds -> comm ) { err = MPI_Barrier ( * ds -> comm ) ; assert ( err == MPI_SUCCESS ) ; } else { err = PMI_Barrier ( ) ; assert ( err == PMI_SUCCESS ) ; } uloga ( " \n " , __func__ , ds -> self -> ptlmap . id ) ; return ds ; err_free_dsrv : uloga ( " \n " , __func__ , err ) ; free ( ds ) ; return NULL ; err_out : uloga ( " \n " , __func__ , err ) ; return NULL ; }
Allocate and initialize dart server; the server initializes rpc
server.
Allocate and initialize dart server ; the server initializes rpc server .
//peer_size represents current number of peers in total
 ////DSaaS
 // If there is a single server, mark it as registered, but it should also be master!
