Skip to content

Commit f9d685f

Browse files
authored
Merge pull request pmodels#7249 from hzhou/2412_CHKLMEM
mpir_mem: simplify MPIR_CHKLMEM_ macros Approved-by: Ken Raffenetti
2 parents fa613a1 + 0660ece commit f9d685f

File tree

139 files changed

+698
-1025
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+698
-1025
lines changed

CHANGES

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
===============================================================================
2+
Changes in 5.0
3+
===============================================================================
4+
# MPIR_CHKLMEM_ and MPIR_CHKPMEM_ macros are simplified, removing non-essential
5+
argument such as type case and custom error messages.
6+
17
===============================================================================
28
Changes in 4.3
39
===============================================================================

src/include/mpir_mem.h

Lines changed: 63 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -103,98 +103,83 @@ extern "C" {
103103
#define MPIR_CHKMEM_SETERR(rc_,nbytes_,name_) rc_=MPI_ERR_OTHER
104104
#endif /* HAVE_ERROR_CHECKING */
105105

106-
/* CHKPMEM_REGISTER is used for memory allocated within another routine */
107-
108-
#define MPIR_CHKLMEM_DECL(n_) \
109-
void *(mpiu_chklmem_stk_[n_]) = { NULL }; \
110-
int mpiu_chklmem_stk_sp_=0; \
111-
MPIR_AssertDeclValue(const int mpiu_chklmem_stk_sz_,n_)
112-
113-
#define MPIR_CHKLMEM_MALLOC_ORSTMT(pointer_,type_,nbytes_,rc_,name_,class_,stmt_) \
114-
{ \
115-
pointer_ = (type_)MPL_malloc(nbytes_,class_); \
116-
if (pointer_) { \
117-
MPIR_Assert(mpiu_chklmem_stk_sp_<mpiu_chklmem_stk_sz_); \
118-
mpiu_chklmem_stk_[mpiu_chklmem_stk_sp_++] = (void *) pointer_; \
119-
} else if (nbytes_ > 0) { \
120-
MPIR_CHKMEM_SETERR(rc_,nbytes_,name_); \
121-
stmt_; \
122-
} \
123-
}
106+
107+
#define MPIR_CHKLMEM_MAX 10
108+
#define MPIR_CHKLMEM_DECL() \
109+
void *(mpiu_chklmem_stk_[MPIR_CHKLMEM_MAX]) = { NULL }; \
110+
int mpiu_chklmem_stk_sp_=0;
111+
112+
#define MPIR_CHKLMEM_REGISTER(pointer_) \
113+
do { \
114+
MPIR_Assert(mpiu_chklmem_stk_sp_<MPIR_CHKLMEM_MAX); \
115+
mpiu_chklmem_stk_[mpiu_chklmem_stk_sp_++] = pointer_; \
116+
} while (0)
117+
118+
#define MPIR_CHKLMEM_MALLOC(pointer_,nbytes_) \
119+
do { \
120+
pointer_ = MPL_malloc(nbytes_,MPL_MEM_LOCAL); \
121+
if (pointer_) { \
122+
MPIR_Assert(mpiu_chklmem_stk_sp_<MPIR_CHKLMEM_MAX); \
123+
mpiu_chklmem_stk_[mpiu_chklmem_stk_sp_++] = pointer_; \
124+
} else if (nbytes_ > 0) { \
125+
MPIR_ERR_SETANDJUMP(mpi_errno, MPI_ERR_OTHER, "**nomem"); \
126+
} \
127+
} while (0)
128+
124129
#define MPIR_CHKLMEM_FREEALL() \
125130
do { \
126131
while (mpiu_chklmem_stk_sp_ > 0) { \
127132
MPL_free(mpiu_chklmem_stk_[--mpiu_chklmem_stk_sp_]); \
128133
} \
129134
} while (0)
130135

131-
#define MPIR_CHKLMEM_MALLOC(pointer_,type_,nbytes_,rc_,name_,class_) \
132-
MPIR_CHKLMEM_MALLOC_ORJUMP(pointer_,type_,nbytes_,rc_,name_,class_)
133-
#define MPIR_CHKLMEM_MALLOC_ORJUMP(pointer_,type_,nbytes_,rc_,name_,class_) \
134-
MPIR_CHKLMEM_MALLOC_ORSTMT(pointer_,type_,nbytes_,rc_,name_,class_,goto fn_fail)
135136

136137
/* Persistent memory that we may want to recover if something goes wrong */
137-
#define MPIR_CHKPMEM_DECL(n_) \
138-
void *(mpiu_chkpmem_stk_[n_]) = { NULL }; \
139-
int mpiu_chkpmem_stk_sp_=0; \
140-
MPIR_AssertDeclValue(const int mpiu_chkpmem_stk_sz_,n_)
141-
#define MPIR_CHKPMEM_MALLOC_ORSTMT(pointer_,type_,nbytes_,rc_,name_,class_,stmt_) \
142-
{ \
143-
pointer_ = (type_)MPL_malloc(nbytes_,class_); \
144-
if (pointer_) { \
145-
MPIR_Assert(mpiu_chkpmem_stk_sp_<mpiu_chkpmem_stk_sz_); \
146-
mpiu_chkpmem_stk_[mpiu_chkpmem_stk_sp_++] = pointer_; \
147-
} else if (nbytes_ > 0) { \
148-
MPIR_CHKMEM_SETERR(rc_,nbytes_,name_); \
149-
stmt_; \
150-
} \
151-
}
152-
#define MPIR_CHKPMEM_REGISTER(pointer_) \
153-
{ \
154-
MPIR_Assert(mpiu_chkpmem_stk_sp_<mpiu_chkpmem_stk_sz_); \
155-
mpiu_chkpmem_stk_[mpiu_chkpmem_stk_sp_++] = pointer_; \
156-
}
157-
#define MPIR_CHKPMEM_REAP() \
158-
{ \
159-
while (mpiu_chkpmem_stk_sp_ > 0) { \
160-
MPL_free(mpiu_chkpmem_stk_[--mpiu_chkpmem_stk_sp_]); \
161-
} \
162-
}
163-
#define MPIR_CHKPMEM_COMMIT() \
138+
#define MPIR_CHKPMEM_MAX 10
139+
#define MPIR_CHKPMEM_DECL() \
140+
void *(mpiu_chkpmem_stk_[MPIR_CHKPMEM_MAX]) = { NULL }; \
141+
int mpiu_chkpmem_stk_sp_=0;
142+
143+
#define MPIR_CHKPMEM_MALLOC(pointer_,nbytes_,class_) \
144+
do { \
145+
pointer_ = MPL_malloc(nbytes_,class_); \
146+
if (pointer_) { \
147+
MPIR_Assert(mpiu_chkpmem_stk_sp_<MPIR_CHKPMEM_MAX); \
148+
mpiu_chkpmem_stk_[mpiu_chkpmem_stk_sp_++] = pointer_; \
149+
} else if (nbytes_ > 0) { \
150+
MPIR_ERR_SETANDJUMP(mpi_errno, MPI_ERR_OTHER, "**nomem"); \
151+
} \
152+
} while (0)
153+
154+
#define MPIR_CHKPMEM_REGISTER(pointer_) \
155+
do { \
156+
MPIR_Assert(mpiu_chkpmem_stk_sp_<MPIR_CHKPMEM_MAX); \
157+
mpiu_chkpmem_stk_[mpiu_chkpmem_stk_sp_++] = pointer_; \
158+
} while (0)
159+
160+
#define MPIR_CHKPMEM_REAP() \
161+
do { \
162+
while (mpiu_chkpmem_stk_sp_ > 0) { \
163+
MPL_free(mpiu_chkpmem_stk_[--mpiu_chkpmem_stk_sp_]); \
164+
} \
165+
} while (0)
166+
167+
/* NOTE: unnecessary to commit if all memory allocations need be freed at fail */
168+
#define MPIR_CHKPMEM_COMMIT() \
164169
mpiu_chkpmem_stk_sp_ = 0
165-
#define MPIR_CHKPMEM_MALLOC(pointer_,type_,nbytes_,rc_,name_,class_) \
166-
MPIR_CHKPMEM_MALLOC_ORJUMP(pointer_,type_,nbytes_,rc_,name_,class_)
167-
#define MPIR_CHKPMEM_MALLOC_ORJUMP(pointer_,type_,nbytes_,rc_,name_,class_) \
168-
MPIR_CHKPMEM_MALLOC_ORSTMT(pointer_,type_,nbytes_,rc_,name_,class_,goto fn_fail)
169170

170171
/* now the CALLOC version for zeroed memory */
171-
#define MPIR_CHKPMEM_CALLOC(pointer_,type_,nbytes_,rc_,name_,class_) \
172-
MPIR_CHKPMEM_CALLOC_ORJUMP(pointer_,type_,nbytes_,rc_,name_,class_)
173-
#define MPIR_CHKPMEM_CALLOC_ORJUMP(pointer_,type_,nbytes_,rc_,name_,class_) \
174-
MPIR_CHKPMEM_CALLOC_ORSTMT(pointer_,type_,nbytes_,rc_,name_,class_,goto fn_fail)
175-
#define MPIR_CHKPMEM_CALLOC_ORSTMT(pointer_,type_,nbytes_,rc_,name_,class_,stmt_) \
176-
do { \
177-
pointer_ = (type_)MPL_calloc(1, (nbytes_), (class_)); \
178-
if (pointer_) { \
179-
MPIR_Assert(mpiu_chkpmem_stk_sp_<mpiu_chkpmem_stk_sz_); \
180-
mpiu_chkpmem_stk_[mpiu_chkpmem_stk_sp_++] = pointer_; \
181-
} \
182-
else if (nbytes_ > 0) { \
183-
MPIR_CHKMEM_SETERR(rc_,nbytes_,name_); \
184-
stmt_; \
185-
} \
172+
#define MPIR_CHKPMEM_CALLOC(pointer_,nbytes_,class_) \
173+
do { \
174+
pointer_ = MPL_calloc(1, nbytes_, class_); \
175+
if (pointer_) { \
176+
MPIR_Assert(mpiu_chkpmem_stk_sp_<MPIR_CHKPMEM_MAX); \
177+
mpiu_chkpmem_stk_[mpiu_chkpmem_stk_sp_++] = pointer_; \
178+
} else if (nbytes_ > 0) { \
179+
MPIR_ERR_SETANDJUMP(mpi_errno, MPI_ERR_OTHER, "**nomem"); \
180+
} \
186181
} while (0)
187182

188-
/* A special version for routines that only allocate one item */
189-
#define MPIR_CHKPMEM_MALLOC1(pointer_,type_,nbytes_,rc_,name_,class_,stmt_) \
190-
{ \
191-
pointer_ = (type_)MPL_malloc(nbytes_,class_); \
192-
if (!(pointer_) && (nbytes_ > 0)) { \
193-
MPIR_CHKMEM_SETERR(rc_,nbytes_,name_); \
194-
stmt_; \
195-
} \
196-
}
197-
198183
/* Provides a easy way to use realloc safely and avoid the temptation to use
199184
* realloc unsafely (direct ptr assignment). Zero-size reallocs returning NULL
200185
* are handled and are not considered an error. */

src/mpi/coll/algorithms/recexchalgo/recexchalgo.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ int MPII_Recexchalgo_reverse_digits_step2(int rank, int comm_size, int k)
331331
int pofk = 1, log_pofk = 0;
332332
int *digit, *digit_reverse;
333333
int mpi_errno ATTRIBUTE((unused)) = MPI_SUCCESS;
334-
MPIR_CHKLMEM_DECL(2);
334+
MPIR_CHKLMEM_DECL();
335335

336336
MPIR_FUNC_ENTER;
337337

@@ -350,10 +350,8 @@ int MPII_Recexchalgo_reverse_digits_step2(int rank, int comm_size, int k)
350350
step2rank = MPII_Recexchalgo_origrank_to_step2rank(rank, rem, T, k);
351351

352352
/* calculate the digits in base k representation of step2rank */
353-
MPIR_CHKLMEM_MALLOC(digit, int *, sizeof(int) * log_pofk,
354-
mpi_errno, "digit buffer", MPL_MEM_COLL);
355-
MPIR_CHKLMEM_MALLOC(digit_reverse, int *, sizeof(int) * log_pofk,
356-
mpi_errno, "digit_reverse buffer", MPL_MEM_COLL);
353+
MPIR_CHKLMEM_MALLOC(digit, sizeof(int) * log_pofk);
354+
MPIR_CHKLMEM_MALLOC(digit_reverse, sizeof(int) * log_pofk);
357355
for (i = 0; i < log_pofk; i++)
358356
digit[i] = 0;
359357

src/mpi/coll/allgather/allgather_inter_local_gather_remote_bcast.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ int MPIR_Allgather_inter_local_gather_remote_bcast(const void *sendbuf, MPI_Aint
2222
void *tmp_buf = NULL;
2323
MPIR_Comm *newcomm_ptr = NULL;
2424

25-
MPIR_CHKLMEM_DECL(1);
25+
MPIR_CHKLMEM_DECL();
2626

2727
local_size = comm_ptr->local_size;
2828
remote_size = comm_ptr->remote_size;
@@ -32,8 +32,7 @@ int MPIR_Allgather_inter_local_gather_remote_bcast(const void *sendbuf, MPI_Aint
3232
/* In each group, rank 0 allocates temp. buffer for local
3333
* gather */
3434
MPIR_Datatype_get_size_macro(sendtype, sendtype_sz);
35-
MPIR_CHKLMEM_MALLOC(tmp_buf, void *, sendcount * sendtype_sz * local_size, mpi_errno,
36-
"tmp_buf", MPL_MEM_BUFFER);
35+
MPIR_CHKLMEM_MALLOC(tmp_buf, sendcount * sendtype_sz * local_size);
3736
} else {
3837
/* silence -Wmaybe-uninitialized due to MPIR_{Gather,Bcast} calls by non-zero ranks */
3938
sendtype_sz = 0;

src/mpi/coll/allgather/allgather_intra_brucks.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ int MPIR_Allgather_intra_brucks(const void *sendbuf,
2828
void *tmp_buf = NULL;
2929
int dst;
3030

31-
MPIR_CHKLMEM_DECL(1);
31+
MPIR_CHKLMEM_DECL();
3232

3333
if (((sendcount == 0) && (sendbuf != MPI_IN_PLACE)) || (recvcount == 0))
3434
goto fn_exit;
@@ -39,8 +39,7 @@ int MPIR_Allgather_intra_brucks(const void *sendbuf,
3939
MPIR_Datatype_get_size_macro(recvtype, recvtype_sz);
4040

4141
/* allocate a temporary buffer of the same size as recvbuf. */
42-
MPIR_CHKLMEM_MALLOC(tmp_buf, void *, recvcount * comm_size * recvtype_sz, mpi_errno,
43-
"tmp_buf", MPL_MEM_BUFFER);
42+
MPIR_CHKLMEM_MALLOC(tmp_buf, recvcount * comm_size * recvtype_sz);
4443

4544
/* copy local data to the top of tmp_buf */
4645
if (sendbuf != MPI_IN_PLACE) {

src/mpi/coll/allgather/allgather_intra_k_brucks.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ MPIR_Allgather_intra_k_brucks(const void *sendbuf, MPI_Aint sendcount,
4747

4848
int delta = 1;
4949
void *tmp_recvbuf = NULL;
50-
MPIR_CHKLMEM_DECL(2);
51-
MPIR_CHKLMEM_MALLOC(reqs, MPIR_Request **, (2 * (k - 1) * sizeof(MPIR_Request *)), mpi_errno,
52-
"reqs", MPL_MEM_BUFFER);
50+
MPIR_CHKLMEM_DECL();
51+
MPIR_CHKLMEM_MALLOC(reqs, (2 * (k - 1) * sizeof(MPIR_Request *)));
5352

5453
MPL_DBG_MSG_FMT(MPIR_DBG_COLL, VERBOSE, (MPL_DBG_FDEST,
5554
"Allgather_brucks_radix_k algorithm: num_ranks: %d, k: %d",

src/mpi/coll/allgatherv/allgatherv_intra_brucks.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ int MPIR_Allgatherv_intra_brucks(const void *sendbuf,
3232
int pof2, src, dst, rem;
3333
MPI_Aint curr_cnt, send_cnt, recv_cnt, total_count;
3434
void *tmp_buf;
35-
MPIR_CHKLMEM_DECL(1);
35+
MPIR_CHKLMEM_DECL();
3636

3737
MPIR_THREADCOMM_RANK_SIZE(comm_ptr, rank, comm_size);
3838

@@ -48,8 +48,7 @@ int MPIR_Allgatherv_intra_brucks(const void *sendbuf,
4848
/* allocate a temporary buffer that can hold all the data */
4949
MPIR_Datatype_get_size_macro(recvtype, recvtype_sz);
5050

51-
MPIR_CHKLMEM_MALLOC(tmp_buf, void *, total_count * recvtype_sz, mpi_errno, "tmp_buf",
52-
MPL_MEM_BUFFER);
51+
MPIR_CHKLMEM_MALLOC(tmp_buf, total_count * recvtype_sz);
5352

5453
/* copy local data to the top of tmp_buf */
5554
if (sendbuf != MPI_IN_PLACE) {

src/mpi/coll/allgatherv/allgatherv_intra_recursive_doubling.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ int MPIR_Allgatherv_intra_recursive_doubling(const void *sendbuf,
3636
void *tmp_buf;
3737
int mask, dst_tree_root, my_tree_root, nprocs_completed, k, tmp_mask, tree_root;
3838
MPI_Aint position, send_offset, recv_offset, offset;
39-
MPIR_CHKLMEM_DECL(1);
39+
MPIR_CHKLMEM_DECL();
4040

4141
comm_size = comm_ptr->local_size;
4242
rank = comm_ptr->rank;
@@ -58,8 +58,7 @@ int MPIR_Allgatherv_intra_recursive_doubling(const void *sendbuf,
5858
MPIR_Datatype_get_extent_macro(recvtype, recvtype_extent);
5959
MPIR_Datatype_get_size_macro(recvtype, recvtype_sz);
6060

61-
MPIR_CHKLMEM_MALLOC(tmp_buf, void *,
62-
total_count * recvtype_sz, mpi_errno, "tmp_buf", MPL_MEM_BUFFER);
61+
MPIR_CHKLMEM_MALLOC(tmp_buf, total_count * recvtype_sz);
6362

6463
/* copy local data into right location in tmp_buf */
6564
position = 0;

src/mpi/coll/allreduce/allreduce_inter_reduce_exchange_bcast.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,16 @@ int MPIR_Allreduce_inter_reduce_exchange_bcast(const void *sendbuf, void *recvbu
1717
MPI_Datatype datatype, MPI_Op op,
1818
MPIR_Comm * comm_ptr, MPIR_Errflag_t errflag)
1919
{
20-
int mpi_errno;
20+
int mpi_errno = MPI_SUCCESS;
2121
MPI_Aint true_extent, true_lb, extent;
2222
void *tmp_buf = NULL;
2323
MPIR_Comm *newcomm_ptr = NULL;
24-
MPIR_CHKLMEM_DECL(1);
24+
MPIR_CHKLMEM_DECL();
2525

2626
if (comm_ptr->rank == 0) {
2727
MPIR_Type_get_true_extent_impl(datatype, &true_lb, &true_extent);
2828
MPIR_Datatype_get_extent_macro(datatype, extent);
29-
MPIR_CHKLMEM_MALLOC(tmp_buf, void *, count * (MPL_MAX(extent, true_extent)), mpi_errno,
30-
"temporary buffer", MPL_MEM_BUFFER);
29+
MPIR_CHKLMEM_MALLOC(tmp_buf, count * (MPL_MAX(extent, true_extent)));
3130
/* adjust for potential negative lower bound in datatype */
3231
tmp_buf = (void *) ((char *) tmp_buf - true_lb);
3332
}

src/mpi/coll/allreduce/allreduce_intra_k_reduce_scatter_allgather.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ int MPIR_Allreduce_intra_k_reduce_scatter_allgather(const void *sendbuf,
3232
MPIR_Request **send_reqs = NULL, **recv_reqs = NULL;
3333
int num_sreq = 0, num_rreq = 0, total_phases = 0;
3434
void *tmp_recvbuf = NULL;
35-
MPIR_CHKLMEM_DECL(2);
35+
MPIR_CHKLMEM_DECL();
3636

3737
MPIR_Assert(k > 1);
3838

@@ -123,10 +123,8 @@ int MPIR_Allreduce_intra_k_reduce_scatter_allgather(const void *sendbuf,
123123
/* Main recursive exchange step */
124124
if (in_step2) {
125125
MPI_Aint *cnts = NULL, *displs = NULL;
126-
MPIR_CHKLMEM_MALLOC(cnts, MPI_Aint *, sizeof(MPI_Aint) * nranks, mpi_errno, "cnts",
127-
MPL_MEM_COLL);
128-
MPIR_CHKLMEM_MALLOC(displs, MPI_Aint *, sizeof(MPI_Aint) * nranks, mpi_errno, "displs",
129-
MPL_MEM_COLL);
126+
MPIR_CHKLMEM_MALLOC(cnts, sizeof(MPI_Aint) * nranks);
127+
MPIR_CHKLMEM_MALLOC(displs, sizeof(MPI_Aint) * nranks);
130128
idx = 0;
131129
rem = nranks - p_of_k;
132130

0 commit comments

Comments
 (0)