3636
3737MPIDI_POSIX_eager_iqueue_global_t MPIDI_POSIX_eager_iqueue_global ;
3838
39- static int init_transport (int vci_src , int vci_dst )
39+ static int init_transport (void * slab , int vci_src , int vci_dst )
4040{
4141 int mpi_errno = MPI_SUCCESS ;
4242
@@ -51,28 +51,24 @@ static int init_transport(int vci_src, int vci_dst)
5151 MPIDU_GENQ_SHMEM_QUEUE_TYPE__MPSC ,
5252 MPIDU_GENQ_SHMEM_QUEUE_TYPE__MPMC
5353 };
54- mpi_errno = MPIDU_genq_shmem_pool_create (transport -> size_of_cell , transport -> num_cells ,
54+ mpi_errno = MPIDU_genq_shmem_pool_create (slab , MPIDI_POSIX_eager_iqueue_global .slab_size ,
55+ transport -> size_of_cell , transport -> num_cells ,
5556 MPIR_Process .local_size ,
5657 MPIR_Process .local_rank ,
5758 2 , queue_types , & transport -> cell_pool );
5859 MPIR_ERR_CHECK (mpi_errno );
5960 } else {
6061 int queue_type = MPIDU_GENQ_SHMEM_QUEUE_TYPE__MPSC ;
61- mpi_errno = MPIDU_genq_shmem_pool_create (transport -> size_of_cell , transport -> num_cells ,
62+ mpi_errno = MPIDU_genq_shmem_pool_create (slab , MPIDI_POSIX_eager_iqueue_global .slab_size ,
63+ transport -> size_of_cell , transport -> num_cells ,
6264 MPIR_Process .local_size ,
6365 MPIR_Process .local_rank ,
6466 1 , & queue_type , & transport -> cell_pool );
6567 MPIR_ERR_CHECK (mpi_errno );
6668 }
6769
68- size_t size_of_terminals ;
69- /* Create one terminal for each process with which we will be able to communicate. */
70- size_of_terminals = (size_t ) MPIR_Process .local_size * sizeof (MPIDU_genq_shmem_queue_u );
71-
72- /* Create the shared memory regions that will be used for the iqueue cells and terminals. */
73- mpi_errno = MPIDU_Init_shm_alloc (size_of_terminals , (void * ) & transport -> terminals );
74- MPIR_ERR_CHECK (mpi_errno );
75-
70+ transport -> terminals = (void * ) ((char * ) slab +
71+ MPIDI_POSIX_eager_iqueue_global .terminal_offset );
7672 transport -> my_terminal = & transport -> terminals [MPIR_Process .local_rank ];
7773
7874 mpi_errno = MPIDU_genq_shmem_queue_init (transport -> my_terminal ,
@@ -98,7 +94,27 @@ int MPIDI_POSIX_iqueue_init(int rank, int size)
9894 /* Init vci 0. Communication on vci 0 is enabled afterwards. */
9995 MPIDI_POSIX_eager_iqueue_global .max_vcis = 1 ;
10096
101- mpi_errno = init_transport (0 , 0 );
97+ /* calculate needed shmem size per (vci_src, vci_dst) */
98+ int num_free_queue = MPIR_CVAR_CH4_SHM_POSIX_TOPO_ENABLE ? 2 : 1 ;
99+ int cell_size = MPIR_CVAR_CH4_SHM_POSIX_IQUEUE_CELL_SIZE ;
100+ int num_cells = MPIR_CVAR_CH4_SHM_POSIX_IQUEUE_NUM_CELLS ;
101+ int nprocs = MPIR_Process .local_size ;
102+
103+ int pool_size = MPIDU_genq_shmem_pool_size (cell_size , num_cells , nprocs , num_free_queue );
104+ int terminal_size = num_proc * sizeof (MPIDU_genq_shmem_queue_u );
105+
106+ int slab_size = pool_size + terminal_size ;
107+
108+ /* Create the shared memory regions that will be used for the iqueue cells and terminals. */
109+ void * slab ;
110+ mpi_errno = MPIDU_Init_shm_alloc (slab_size , (void * ) & slab );
111+ MPIR_ERR_CHECK (mpi_errno );
112+
113+ MPIDI_POSIX_eager_iqueue_global .slab_size = slab_size ;
114+ MPIDI_POSIX_eager_iqueue_global .terminal_offset = pool_size ;
115+ MPIDI_POSIX_eager_iqueue_global .root_slab = slab ;
116+
117+ mpi_errno = init_transport (slab , 0 , 0 );
102118 MPIR_ERR_CHECK (mpi_errno );
103119
104120 mpi_errno = MPIDU_Init_shm_barrier ();
@@ -127,15 +143,24 @@ int MPIDI_POSIX_iqueue_post_init(void)
127143 }
128144
129145 MPIDI_POSIX_eager_iqueue_global .max_vcis = max_vcis ;
146+ int slab_size = MPIDI_POSIX_eager_iqueue_global .slab_size * max_vcis * max_vcis ;
147+ /* Create the shared memory regions for all vcis */
148+ /* TODO: do shm alloc in a comm */
149+ void * slab ;
150+ mpi_errno = MPIDU_Init_shm_alloc (slab_size , (void * ) & slab );
151+ MPIR_ERR_CHECK (mpi_errno );
152+
153+ MPIDI_POSIX_eager_iqueue_global .all_slab = slab ;
130154
131155 for (int vci_src = 0 ; vci_src < max_vcis ; vci_src ++ ) {
132156 for (int vci_dst = 0 ; vci_dst < max_vcis ; vci_dst ++ ) {
133157 if (vci_src == 0 && vci_dst == 0 ) {
134158 continue ;
135159 }
136- mpi_errno = init_transport (vci_src , vci_dst );
160+ void * p = (char * ) slab + (vci_src * max_vcis + vci_dst ) *
161+ MPIDI_POSIX_eager_iqueue_global .slab_size ;
162+ mpi_errno = init_transport (p , vci_src , vci_dst );
137163 MPIR_ERR_CHECK (mpi_errno );
138-
139164 }
140165 }
141166
@@ -156,18 +181,34 @@ int MPIDI_POSIX_iqueue_finalize(void)
156181
157182 MPIR_FUNC_ENTER ;
158183
184+ if (MPIDI_POSIX_eager_iqueue_global .max_vcis .root_slab ) {
185+ MPIDI_POSIX_eager_iqueue_transport_t * transport ;
186+ transport = MPIDI_POSIX_eager_iqueue_get_transport (vci_src , vci_dst );
187+
188+ mpi_errno = MPIDU_genq_shmem_pool_destroy (transport -> cell_pool );
189+ MPIR_ERR_CHECK (mpi_errno );
190+
191+ mpi_errno = MPIDU_Init_shm_free (MPIDI_POSIX_eager_iqueue_global .max_vcis .root_slab );
192+ MPIR_ERR_CHECK (mpi_errno );
193+ MPIDI_POSIX_eager_iqueue_global .max_vcis .root_slab = NULL ;
194+ }
195+
196+ if (!MPIDI_POSIX_eager_iqueue_global .max_vcis .all_slab ) {
197+ goto fn_exit ;
198+ }
159199 int max_vcis = MPIDI_POSIX_eager_iqueue_global .max_vcis ;
160200 for (int vci_src = 0 ; vci_src < max_vcis ; vci_src ++ ) {
161201 for (int vci_dst = 0 ; vci_dst < max_vcis ; vci_dst ++ ) {
162202 MPIDI_POSIX_eager_iqueue_transport_t * transport ;
163203 transport = MPIDI_POSIX_eager_iqueue_get_transport (vci_src , vci_dst );
164204
165- mpi_errno = MPIDU_Init_shm_free (transport -> terminals );
166- MPIR_ERR_CHECK (mpi_errno );
167205 mpi_errno = MPIDU_genq_shmem_pool_destroy (transport -> cell_pool );
168206 MPIR_ERR_CHECK (mpi_errno );
169207 }
170208 }
209+ mpi_errno = MPIDU_Init_shm_free (MPIDI_POSIX_eager_iqueue_global .max_vcis .all_slab );
210+ MPIR_ERR_CHECK (mpi_errno );
211+ MPIDI_POSIX_eager_iqueue_global .max_vcis .all_slab = NULL ;
171212
172213 fn_exit :
173214 MPIR_FUNC_EXIT ;
0 commit comments