Skip to content

Commit

Permalink
Merge pull request #132 from pmodels/issue-122
Browse files Browse the repository at this point in the history
shmem_calloc needs to allocate count*size not size
  • Loading branch information
yfguo authored Jun 10, 2022
2 parents 8c112d8 + c0c56fe commit 9b00d56
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/include/oshmpi_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions src/internal/mem_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
10 changes: 8 additions & 2 deletions src/shmem/mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 9b00d56

Please sign in to comment.