From c662999d5872383b9b6b1d301ff0ea7486090c72 Mon Sep 17 00:00:00 2001 From: "Victor A. P. Magri" <50467563+victorapm@users.noreply.github.com> Date: Thu, 30 Nov 2023 18:07:35 -0500 Subject: [PATCH] Fix tux regressions (#1018) Fix allocation issue with hypre_CreateBinaryTree --- src/utilities/_hypre_utilities.h | 3 +- src/utilities/exchange_data.c | 60 ++++++++++++++++++++------------ src/utilities/exchange_data.h | 3 +- 3 files changed, 40 insertions(+), 26 deletions(-) diff --git a/src/utilities/_hypre_utilities.h b/src/utilities/_hypre_utilities.h index a629a85b3..513623a8d 100644 --- a/src/utilities/_hypre_utilities.h +++ b/src/utilities/_hypre_utilities.h @@ -1661,7 +1661,7 @@ typedef struct } hypre_DataExchangeResponse; -HYPRE_Int hypre_CreateBinaryTree(HYPRE_Int, HYPRE_Int, hypre_BinaryTree*); +HYPRE_Int hypre_CreateBinaryTree(HYPRE_Int, HYPRE_Int, hypre_BinaryTree**); HYPRE_Int hypre_DestroyBinaryTree(hypre_BinaryTree*); HYPRE_Int hypre_DataExchangeList(HYPRE_Int num_contacts, HYPRE_Int *contact_proc_list, void *contact_send_buf, HYPRE_Int *contact_send_buf_starts, HYPRE_Int contact_obj_size, @@ -1669,7 +1669,6 @@ HYPRE_Int hypre_DataExchangeList(HYPRE_Int num_contacts, HYPRE_Int *contact_proc HYPRE_Int rnum, MPI_Comm comm, void **p_response_recv_buf, HYPRE_Int **p_response_recv_buf_starts); #endif /* end of header */ - /****************************************************************************** * Copyright (c) 1998 Lawrence Livermore National Security, LLC and other * HYPRE Project Developers. See the top-level COPYRIGHT file for details. diff --git a/src/utilities/exchange_data.c b/src/utilities/exchange_data.c index b1325f35a..933da2ba6 100644 --- a/src/utilities/exchange_data.c +++ b/src/utilities/exchange_data.c @@ -15,19 +15,25 @@ #include "_hypre_utilities.h" /*--------------------------------------------------- - * hypre_CreateBinaryTree() + * hypre_CreateBinaryTree + * * Get the processors position in the binary tree (i.e., * its children and parent processor ids) *----------------------------------------------------*/ -HYPRE_Int hypre_CreateBinaryTree(HYPRE_Int myid, HYPRE_Int num_procs, - hypre_BinaryTree *tree) +HYPRE_Int +hypre_CreateBinaryTree(HYPRE_Int myid, + HYPRE_Int num_procs, + hypre_BinaryTree **tree_ptr) { + hypre_BinaryTree *tree; HYPRE_Int i, proc, size = 0; HYPRE_Int *tmp_child_id; HYPRE_Int num = 0, parent = 0; - /* initialize*/ + tree = hypre_CTAlloc(hypre_BinaryTree, 1, HYPRE_MEMORY_HOST); + + /* initialize */ proc = myid; /*how many children can a processor have?*/ @@ -37,7 +43,7 @@ HYPRE_Int hypre_CreateBinaryTree(HYPRE_Int myid, HYPRE_Int num_procs, } /* allocate space */ - tmp_child_id = hypre_TAlloc(HYPRE_Int, size, HYPRE_MEMORY_HOST); + tmp_child_id = hypre_TAlloc(HYPRE_Int, size, HYPRE_MEMORY_HOST); /* find children and parent */ for (i = 1; i < num_procs; i *= 2) @@ -56,30 +62,38 @@ HYPRE_Int hypre_CreateBinaryTree(HYPRE_Int myid, HYPRE_Int num_procs, parent = myid - i; break; } - } hypre_BinaryTreeParentId(tree) = parent; hypre_BinaryTreeNumChild(tree) = num; hypre_BinaryTreeChildIds(tree) = tmp_child_id; + *tree_ptr = tree; + return hypre_error_flag; } /*--------------------------------------------------- * hypre_DestroyBinaryTree() - * Destroy storage created by createBinaryTree + * + * Destroy storage created by hypre_CreateBinaryTree *----------------------------------------------------*/ -HYPRE_Int hypre_DestroyBinaryTree(hypre_BinaryTree *tree) -{ - hypre_TFree(hypre_BinaryTreeChildIds(tree), HYPRE_MEMORY_HOST); +HYPRE_Int +hypre_DestroyBinaryTree(hypre_BinaryTree *tree) +{ + if (tree) + { + hypre_TFree(hypre_BinaryTreeChildIds(tree), HYPRE_MEMORY_HOST); + hypre_TFree(tree, HYPRE_MEMORY_HOST); + } return hypre_error_flag; } /*--------------------------------------------------- * hypre_DataExchangeList() + * * This function is for sending a list of messages ("contacts" to * a list of processors. The receiving processors * do not know how many messages they are getting. The @@ -90,17 +104,19 @@ HYPRE_Int hypre_DestroyBinaryTree(hypre_BinaryTree *tree) /* should change to where the buffers for sending and receiving are voids instead of ints - then cast accordingly */ -HYPRE_Int hypre_DataExchangeList(HYPRE_Int num_contacts, - HYPRE_Int *contact_proc_list, - void *contact_send_buf, - HYPRE_Int *contact_send_buf_starts, - HYPRE_Int contact_obj_size, - HYPRE_Int response_obj_size, - hypre_DataExchangeResponse *response_obj, - HYPRE_Int max_response_size, - HYPRE_Int rnum, MPI_Comm comm, - void **p_response_recv_buf, - HYPRE_Int **p_response_recv_buf_starts) +HYPRE_Int +hypre_DataExchangeList(HYPRE_Int num_contacts, + HYPRE_Int *contact_proc_list, + void *contact_send_buf, + HYPRE_Int *contact_send_buf_starts, + HYPRE_Int contact_obj_size, + HYPRE_Int response_obj_size, + hypre_DataExchangeResponse *response_obj, + HYPRE_Int max_response_size, + HYPRE_Int rnum, + MPI_Comm comm, + void **p_response_recv_buf, + HYPRE_Int **p_response_recv_buf_starts) { /*------------------------------------------- * parameters: @@ -275,7 +291,7 @@ HYPRE_Int hypre_DataExchangeList(HYPRE_Int num_contacts, if (num_procs > 1) { - hypre_CreateBinaryTree(myid, num_procs, tree); + hypre_CreateBinaryTree(myid, num_procs, &tree); /* we will get a message from all of our children when they have received responses for all of their contacts. diff --git a/src/utilities/exchange_data.h b/src/utilities/exchange_data.h index e585cc01e..ed2531f8e 100644 --- a/src/utilities/exchange_data.h +++ b/src/utilities/exchange_data.h @@ -41,7 +41,7 @@ typedef struct } hypre_DataExchangeResponse; -HYPRE_Int hypre_CreateBinaryTree(HYPRE_Int, HYPRE_Int, hypre_BinaryTree*); +HYPRE_Int hypre_CreateBinaryTree(HYPRE_Int, HYPRE_Int, hypre_BinaryTree**); HYPRE_Int hypre_DestroyBinaryTree(hypre_BinaryTree*); HYPRE_Int hypre_DataExchangeList(HYPRE_Int num_contacts, HYPRE_Int *contact_proc_list, void *contact_send_buf, HYPRE_Int *contact_send_buf_starts, HYPRE_Int contact_obj_size, @@ -49,4 +49,3 @@ HYPRE_Int hypre_DataExchangeList(HYPRE_Int num_contacts, HYPRE_Int *contact_proc HYPRE_Int rnum, MPI_Comm comm, void **p_response_recv_buf, HYPRE_Int **p_response_recv_buf_starts); #endif /* end of header */ -