Fix tux regressions (#1018)

Fix allocation issue with hypre_CreateBinaryTree
This commit is contained in:
Victor A. P. Magri 2023-11-30 18:07:35 -05:00 committed by GitHub
parent a544782335
commit c662999d58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 26 deletions

View File

@ -1661,7 +1661,7 @@ typedef struct
} hypre_DataExchangeResponse; } 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_DestroyBinaryTree(hypre_BinaryTree*);
HYPRE_Int hypre_DataExchangeList(HYPRE_Int num_contacts, HYPRE_Int *contact_proc_list, 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, 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); HYPRE_Int rnum, MPI_Comm comm, void **p_response_recv_buf, HYPRE_Int **p_response_recv_buf_starts);
#endif /* end of header */ #endif /* end of header */
/****************************************************************************** /******************************************************************************
* Copyright (c) 1998 Lawrence Livermore National Security, LLC and other * Copyright (c) 1998 Lawrence Livermore National Security, LLC and other
* HYPRE Project Developers. See the top-level COPYRIGHT file for details. * HYPRE Project Developers. See the top-level COPYRIGHT file for details.

View File

@ -15,18 +15,24 @@
#include "_hypre_utilities.h" #include "_hypre_utilities.h"
/*--------------------------------------------------- /*---------------------------------------------------
* hypre_CreateBinaryTree() * hypre_CreateBinaryTree
*
* Get the processors position in the binary tree (i.e., * Get the processors position in the binary tree (i.e.,
* its children and parent processor ids) * its children and parent processor ids)
*----------------------------------------------------*/ *----------------------------------------------------*/
HYPRE_Int hypre_CreateBinaryTree(HYPRE_Int myid, HYPRE_Int num_procs, HYPRE_Int
hypre_BinaryTree *tree) hypre_CreateBinaryTree(HYPRE_Int myid,
HYPRE_Int num_procs,
hypre_BinaryTree **tree_ptr)
{ {
hypre_BinaryTree *tree;
HYPRE_Int i, proc, size = 0; HYPRE_Int i, proc, size = 0;
HYPRE_Int *tmp_child_id; HYPRE_Int *tmp_child_id;
HYPRE_Int num = 0, parent = 0; HYPRE_Int num = 0, parent = 0;
tree = hypre_CTAlloc(hypre_BinaryTree, 1, HYPRE_MEMORY_HOST);
/* initialize */ /* initialize */
proc = myid; proc = myid;
@ -56,30 +62,38 @@ HYPRE_Int hypre_CreateBinaryTree(HYPRE_Int myid, HYPRE_Int num_procs,
parent = myid - i; parent = myid - i;
break; break;
} }
} }
hypre_BinaryTreeParentId(tree) = parent; hypre_BinaryTreeParentId(tree) = parent;
hypre_BinaryTreeNumChild(tree) = num; hypre_BinaryTreeNumChild(tree) = num;
hypre_BinaryTreeChildIds(tree) = tmp_child_id; hypre_BinaryTreeChildIds(tree) = tmp_child_id;
*tree_ptr = tree;
return hypre_error_flag; return hypre_error_flag;
} }
/*--------------------------------------------------- /*---------------------------------------------------
* hypre_DestroyBinaryTree() * hypre_DestroyBinaryTree()
* Destroy storage created by createBinaryTree *
* Destroy storage created by hypre_CreateBinaryTree
*----------------------------------------------------*/ *----------------------------------------------------*/
HYPRE_Int hypre_DestroyBinaryTree(hypre_BinaryTree *tree)
{
HYPRE_Int
hypre_DestroyBinaryTree(hypre_BinaryTree *tree)
{
if (tree)
{
hypre_TFree(hypre_BinaryTreeChildIds(tree), HYPRE_MEMORY_HOST); hypre_TFree(hypre_BinaryTreeChildIds(tree), HYPRE_MEMORY_HOST);
hypre_TFree(tree, HYPRE_MEMORY_HOST);
}
return hypre_error_flag; return hypre_error_flag;
} }
/*--------------------------------------------------- /*---------------------------------------------------
* hypre_DataExchangeList() * hypre_DataExchangeList()
*
* This function is for sending a list of messages ("contacts" to * This function is for sending a list of messages ("contacts" to
* a list of processors. The receiving processors * a list of processors. The receiving processors
* do not know how many messages they are getting. The * do not know how many messages they are getting. The
@ -90,7 +104,8 @@ HYPRE_Int hypre_DestroyBinaryTree(hypre_BinaryTree *tree)
/* should change to where the buffers for sending and receiving are voids /* should change to where the buffers for sending and receiving are voids
instead of ints - then cast accordingly */ instead of ints - then cast accordingly */
HYPRE_Int hypre_DataExchangeList(HYPRE_Int num_contacts, HYPRE_Int
hypre_DataExchangeList(HYPRE_Int num_contacts,
HYPRE_Int *contact_proc_list, HYPRE_Int *contact_proc_list,
void *contact_send_buf, void *contact_send_buf,
HYPRE_Int *contact_send_buf_starts, HYPRE_Int *contact_send_buf_starts,
@ -98,7 +113,8 @@ HYPRE_Int hypre_DataExchangeList(HYPRE_Int num_contacts,
HYPRE_Int response_obj_size, HYPRE_Int response_obj_size,
hypre_DataExchangeResponse *response_obj, hypre_DataExchangeResponse *response_obj,
HYPRE_Int max_response_size, HYPRE_Int max_response_size,
HYPRE_Int rnum, MPI_Comm comm, HYPRE_Int rnum,
MPI_Comm comm,
void **p_response_recv_buf, void **p_response_recv_buf,
HYPRE_Int **p_response_recv_buf_starts) HYPRE_Int **p_response_recv_buf_starts)
{ {
@ -275,7 +291,7 @@ HYPRE_Int hypre_DataExchangeList(HYPRE_Int num_contacts,
if (num_procs > 1) 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 /* we will get a message from all of our children when they
have received responses for all of their contacts. have received responses for all of their contacts.

View File

@ -41,7 +41,7 @@ typedef struct
} hypre_DataExchangeResponse; } 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_DestroyBinaryTree(hypre_BinaryTree*);
HYPRE_Int hypre_DataExchangeList(HYPRE_Int num_contacts, HYPRE_Int *contact_proc_list, 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, 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); HYPRE_Int rnum, MPI_Comm comm, void **p_response_recv_buf, HYPRE_Int **p_response_recv_buf_starts);
#endif /* end of header */ #endif /* end of header */