diff --git a/src/include/oshmpi_impl.h b/src/include/oshmpi_impl.h index 8693c5b..8ad614b 100644 --- a/src/include/oshmpi_impl.h +++ b/src/include/oshmpi_impl.h @@ -357,6 +357,7 @@ void *OSHMPI_malloc(size_t size); void OSHMPI_free(void *ptr); void *OSHMPI_realloc(void *ptr, size_t size); void *OSHMPI_align(size_t alignment, size_t size); +void *OSHMPI_calloc(size_t count, size_t size); void OSHMPI_strided_initialize(void); void OSHMPI_strided_finalize(void); diff --git a/src/internal/mem_impl.c b/src/internal/mem_impl.c index ad40dda..6a651c6 100644 --- a/src/internal/mem_impl.c +++ b/src/internal/mem_impl.c @@ -70,3 +70,17 @@ void *OSHMPI_align(size_t alignment, size_t size) OSHMPI_barrier_all(); return ptr; } + +void *OSHMPI_calloc(size_t count, size_t size) +{ + void *ptr = NULL; + + OSHMPI_THREAD_ENTER_CS(&OSHMPI_global.symm_heap_mspace_cs); + ptr = mspace_calloc(OSHMPI_global.symm_heap_mspace, count, size); + OSHMPI_THREAD_EXIT_CS(&OSHMPI_global.symm_heap_mspace_cs); + + OSHMPI_DBGMSG("count %ld, size %ld, ptr %p, disp 0x%lx\n", count, size, ptr, + (MPI_Aint) ptr - (MPI_Aint) OSHMPI_global.symm_heap_attr.base); + OSHMPI_barrier_all(); + return ptr; +} diff --git a/src/shmem/mem.c b/src/shmem/mem.c index 661e706..d556215 100644 --- a/src/shmem/mem.c +++ b/src/shmem/mem.c @@ -47,9 +47,15 @@ void *shmem_calloc(size_t count, size_t size) { void *ptr = NULL; + /* OpenSHMEM 1.5 Section 9.3.3: + * When count or size is 0, the shmem_calloc routine returns without performing a barrier. + * Otherwise, this routine calls a procedure that is semantically equivalent to shmem_barrier_all on exit. */ + if ((count == 0) || (size == 0)) { + return ptr; + } + OSHMPI_NOINLINE_RECURSIVE() - ptr = OSHMPI_malloc(size); - memset(ptr, 0, count * size); + ptr = OSHMPI_calloc(count, size); return ptr; }