Skip to content

Commit

Permalink
more renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyangzhuan committed Dec 8, 2023
1 parent 4bad9d3 commit fb8cb39
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 177 deletions.
160 changes: 6 additions & 154 deletions SRC/double/d3DPartition.c
Original file line number Diff line number Diff line change
@@ -1,112 +1,18 @@
#include "superlu_ddefs.h"

sForest_t **compute_sForests(int_t nsupers, dLUstruct_t *LUstruct, gridinfo3d_t *grid3d)
{
// Calculation of supernodal etree
int_t *setree = supernodal_etree(nsupers, LUstruct->etree, LUstruct->Glu_persist->supno, LUstruct->Glu_persist->xsup);

// Conversion of supernodal etree to list
treeList_t *treeList = setree2list(nsupers, setree);

// Calculation of tree weight
calcTreeWeight(nsupers, setree, treeList, LUstruct->Glu_persist->xsup);

// Calculation of maximum level
int_t maxLvl = log2i(grid3d->zscp.Np) + 1;

// Generation of forests
sForest_t **sForests = getForests(maxLvl, nsupers, setree, treeList);

// Allocate trf3d data structure
// LUstruct->trf3Dpart = (dtrf3Dpartition_t *)SUPERLU_MALLOC(sizeof(dtrf3Dpartition_t));
// dtrf3Dpartition_t *trf3Dpart = LUstruct->trf3Dpart;

return sForests;
}


gEtreeInfo_t fillEtreeInfo( int_t nsupers, int_t* setree, treeList_t *treeList) {

gEtreeInfo_t gEtreeInfo;
gEtreeInfo.setree = setree;
gEtreeInfo.numChildLeft = (int_t *)SUPERLU_MALLOC(sizeof(int_t) * nsupers);
for (int_t i = 0; i < nsupers; ++i)
{
gEtreeInfo.numChildLeft[i] = treeList[i].numChild;
}

return gEtreeInfo;
}

int_t* create_iperm_c_supno(int_t nsupers, superlu_dist_options_t *options,
dLUstruct_t *LUstruct, gridinfo3d_t *grid3d) {
gridinfo_t *grid = &(grid3d->grid2d);
int_t *perm_c_supno = getPerm_c_supno(nsupers, options,
LUstruct->etree,
LUstruct->Glu_persist,
LUstruct->Llu->Lrowind_bc_ptr,
LUstruct->Llu->Ufstnz_br_ptr, grid);
int_t *iperm_c_supno = getFactIperm(perm_c_supno, nsupers);
SUPERLU_FREE(perm_c_supno);
return iperm_c_supno;
}

int_t *createSupernode2TreeMap(int_t nsupers, int_t maxLvl, int_t *gNodeCount, int_t **gNodeLists)
{
int_t *supernode2treeMap = SUPERLU_MALLOC(nsupers * sizeof(int_t));
int_t numForests = (1 << maxLvl) - 1;

for (int_t Fr = 0; Fr < numForests; ++Fr)
{
for (int_t nd = 0; nd < gNodeCount[Fr]; ++nd)
{
supernode2treeMap[gNodeLists[Fr][nd]] = Fr;
}
}

return supernode2treeMap;
}

SupernodeToGridMap_t* createSuperGridMap(int_t nsuper,int_t maxLvl, int_t *myTreeIdxs,
int_t *myZeroTrIdxs, int_t* gNodeCount, int_t** gNodeLists)
{
SupernodeToGridMap_t* superGridMap = SUPERLU_MALLOC(nsuper * sizeof(SupernodeToGridMap_t));
for (int_t i = 0; i < nsuper; ++i)
{
/* initialize with NOT_IN_GRID */
superGridMap[i] = NOT_IN_GRID;
}


for(int_t lvl =0; lvl<maxLvl; lvl++ )
{
int_t treeIdx = myTreeIdxs[lvl];
int_t zeroTrIdx = myZeroTrIdxs[lvl];

for (int_t nd = 0; nd < gNodeCount[treeIdx]; ++nd)
{
/* code */
if(zeroTrIdx)
superGridMap[gNodeLists[treeIdx][nd]] = IN_GRID_ZERO;
else
superGridMap[gNodeLists[treeIdx][nd]] = IN_GRID_AIJ;
}
}
return superGridMap;
}
void newTrfPartitionInit(int_t nsupers, dLUstruct_t *LUstruct, gridinfo3d_t *grid3d)
void dnewTrfPartitionInit(int_t nsupers, dLUstruct_t *LUstruct, gridinfo3d_t *grid3d)
{

gridinfo_t* grid = &(grid3d->grid2d);
int iam = grid3d->iam;
#if ( DEBUGlevel>=1 )
CHECK_MALLOC (iam, "Enter newTrfPartitionInit()");
CHECK_MALLOC (iam, "Enter dnewTrfPartitionInit()");
#endif

// check parameters
if (LUstruct->trf3Dpart == NULL || grid3d == NULL)
{
fprintf(stderr, "Error: Invalid arguments to newTrfPartitionInit().\n");
fprintf(stderr, "Error: Invalid arguments to dnewTrfPartitionInit().\n");
return;
}

Expand Down Expand Up @@ -267,70 +173,16 @@ void newTrfPartitionInit(int_t nsupers, dLUstruct_t *LUstruct, gridinfo3d_t *gr
SUPERLU_FREE(gNodeLists);
free_treelist(nsupers, treeList);
#if ( DEBUGlevel>=1 )
CHECK_MALLOC (iam, "Exit newTrfPartitionInit()");
CHECK_MALLOC (iam, "Exit dnewTrfPartitionInit()");
#endif

}

/**
* @file allocBcastArray.c
* @brief Function to allocate and broadcast an array in a MPI environment.
*/

#include <mpi.h>
#include <stdlib.h>

/**
* @brief Allocates and broadcasts an array in a MPI environment.
*
* This function sends the size from the root process to all other processes in
* the communicator. If the process is not the root, it receives the size from
* the root and allocates the array. Then, the function broadcasts the array
* from the root process to all other processes in the communicator.
*
* @param array Pointer to the array to be allocated and broadcasted.
* @param size The size of the array.
* @param comm The MPI communicator.
* @param root The root process.
*/
void allocBcastArray(void **array, int size, int root, MPI_Comm comm)
{
int rank;
MPI_Comm_rank(comm, &rank); // Get the rank of the current process

// Check if the size is valid
if (rank == root)
{
if (size <= 0)
{
fprintf(stderr, "Error: Size should be a positive integer.\n");
MPI_Abort(comm, EXIT_FAILURE);
}

}

// Send the size from root to all other processes in the communicator
MPI_Bcast(&size, 1, MPI_INT, root, comm);

// If I am not the root, receive the size from the root and allocate the array
if (rank != root)
{
*array = SUPERLU_MALLOC(size);
if (*array == NULL)
{
fprintf(stderr, "Error: Failed to allocate memory.\n");
MPI_Abort(comm, EXIT_FAILURE);
}
}

// Then broadcast the array from the root to all other processes
MPI_Bcast(*array, size, MPI_BYTE, root, comm);
}

// function to broad permuted sparse matrix and symbolic factorization data from
// 2d to 3d grid

void bcastPermutedSparseA(SuperMatrix *A,
void dbcastPermutedSparseA(SuperMatrix *A,
dScalePermstruct_t *ScalePermstruct,
Glu_freeable_t *Glu_freeable,
dLUstruct_t *LUstruct, gridinfo3d_t *grid3d)
Expand All @@ -345,7 +197,7 @@ void bcastPermutedSparseA(SuperMatrix *A,
Glu_freeable == NULL || LUstruct == NULL || grid3d == NULL ||
Glu_persist == NULL || Llu == NULL || Astore == NULL)
{
fprintf(stderr, "Error: Invalid arguments to bcastPermutedSparseA().\n");
fprintf(stderr, "Error: Invalid arguments to dbcastPermutedSparseA().\n");
return;
}

Expand Down
6 changes: 5 additions & 1 deletion SRC/double/pddistribute3d.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ at the top-level directory.
#include "gpu_api_utils.h"
#endif
#include "pddistribute3d.h"



#if 0
/*! \brief
*
* <pre>
Expand Down Expand Up @@ -1355,7 +1359,7 @@ float pddistribute3d(superlu_dist_options_t *options, int_t n, SuperMatrix *A,
return (mem_use + memTRS);

} /* PDDISTRIBUTE3D */

#endif


float
Expand Down
11 changes: 6 additions & 5 deletions SRC/double/pdgssvx3d.c
Original file line number Diff line number Diff line change
Expand Up @@ -1075,12 +1075,12 @@ void pdgssvx3d(superlu_dist_options_t *options, SuperMatrix *A,
SUPERLU_MALLOC(sizeof(Glu_freeable_t))))
ABORT("Malloc fails for Glu_freeable.");
}
bcastPermutedSparseA(A,
dbcastPermutedSparseA(A,
ScalePermstruct,
Glu_freeable,
LUstruct, grid3d);
}else{
//TODO: need a parmetis version of bcastPermutedSparseA broadcasting Pslu_freeable
//TODO: need a parmetis version of dbcastPermutedSparseA broadcasting Pslu_freeable
}
}

Expand Down Expand Up @@ -1113,7 +1113,7 @@ void pdgssvx3d(superlu_dist_options_t *options, SuperMatrix *A,
LUstruct->trf3Dpart = SUPERLU_MALLOC(sizeof(dtrf3Dpartition_t));
// computes the new partition for 3D factorization here
trf3Dpartition=LUstruct->trf3Dpart;
newTrfPartitionInit(nsupers, LUstruct, grid3d);
dnewTrfPartitionInit(nsupers, LUstruct, grid3d);
}
}

Expand Down Expand Up @@ -1177,9 +1177,10 @@ void pdgssvx3d(superlu_dist_options_t *options, SuperMatrix *A,
dLUValSubBuf_t *LUvsb = SUPERLU_MALLOC(sizeof(dLUValSubBuf_t));
dLluBufInit(LUvsb, LUstruct);
trf3Dpartition->LUvsb = LUvsb;
trf3Dpartition->iperm_c_supno = create_iperm_c_supno(nsupers, options, LUstruct, grid3d);
trf3Dpartition->iperm_c_supno = create_iperm_c_supno(nsupers, options, LUstruct->Glu_persist, LUstruct->etree, LUstruct->Llu->Lrowind_bc_ptr, LUstruct->Llu->Ufstnz_br_ptr, grid3d);
}




/*if (!iam) printf ("\tDISTRIBUTE time %8.2f\n", stat->utime[DIST]); */

Expand Down
4 changes: 2 additions & 2 deletions SRC/double/pdgssvx3d_1pass_Yang.c
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,7 @@ void pdgssvx3d(superlu_dist_options_t *options, SuperMatrix *A,

if(Fact != SamePattern_SameRowPerm){
LUstruct->trf3Dpart = SUPERLU_MALLOC(sizeof(dtrf3Dpartition_t));
newTrfPartitionInit(nsupers, LUstruct, grid3d);
dnewTrfPartitionInit(nsupers, LUstruct, grid3d);
trf3Dpartition=LUstruct->trf3Dpart;
}

Expand All @@ -1161,7 +1161,7 @@ void pdgssvx3d(superlu_dist_options_t *options, SuperMatrix *A,
dLUValSubBuf_t *LUvsb = SUPERLU_MALLOC(sizeof(dLUValSubBuf_t));
dLluBufInit(LUvsb, LUstruct);
trf3Dpartition->LUvsb = LUvsb;
trf3Dpartition->iperm_c_supno = create_iperm_c_supno(nsupers, options, LUstruct, grid3d);
trf3Dpartition->iperm_c_supno = create_iperm_c_supno(nsupers, options, LUstruct->Glu_persist, LUstruct->etree, LUstruct->Llu->Lrowind_bc_ptr, LUstruct->Llu->Ufstnz_br_ptr, grid3d);
}


Expand Down
8 changes: 4 additions & 4 deletions SRC/double/pdgssvx3d_piyush.c
Original file line number Diff line number Diff line change
Expand Up @@ -1073,12 +1073,12 @@ void pdgssvx3d(superlu_dist_options_t *options, SuperMatrix *A,
SUPERLU_MALLOC(sizeof(Glu_freeable_t))))
ABORT("Malloc fails for Glu_freeable.");
}
bcastPermutedSparseA(A,
dbcastPermutedSparseA(A,
ScalePermstruct,
Glu_freeable,
LUstruct, grid3d);
}else{
//TODO: need a parmetis version of bcastPermutedSparseA broadcasting Pslu_freeable
//TODO: need a parmetis version of dbcastPermutedSparseA broadcasting Pslu_freeable
}
}

Expand Down Expand Up @@ -1111,7 +1111,7 @@ void pdgssvx3d(superlu_dist_options_t *options, SuperMatrix *A,
LUstruct->trf3Dpart = SUPERLU_MALLOC(sizeof(dtrf3Dpartition_t));
// computes the new partition for 3D factorization here
trf3Dpartition=LUstruct->trf3Dpart;
newTrfPartitionInit(nsupers, LUstruct, grid3d);
dnewTrfPartitionInit(nsupers, LUstruct, grid3d);
}
}

Expand Down Expand Up @@ -1175,7 +1175,7 @@ void pdgssvx3d(superlu_dist_options_t *options, SuperMatrix *A,
dLUValSubBuf_t *LUvsb = SUPERLU_MALLOC(sizeof(dLUValSubBuf_t));
dLluBufInit(LUvsb, LUstruct);
trf3Dpartition->LUvsb = LUvsb;
trf3Dpartition->iperm_c_supno = create_iperm_c_supno(nsupers, options, LUstruct, grid3d);
trf3Dpartition->iperm_c_supno = create_iperm_c_supno(nsupers, options, LUstruct->Glu_persist, LUstruct->etree, LUstruct->Llu->Lrowind_bc_ptr, LUstruct->Llu->Ufstnz_br_ptr, grid3d);
}


Expand Down
8 changes: 2 additions & 6 deletions SRC/include/pddistribute3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,13 @@ int_t ComputeLDAspa_Ilsum( int_t nsupers, int_t* ilsum, gridinfo3d_t* grid3d) ;
void propagateDataThroughMatrixBlocks(int_t nsupers, Glu_freeable_t *Glu_freeable, dLUstruct_t *LUstruct, gridinfo3d_t* grid3d,
int_t *Urb_length, int_t *rb_marker, int_t *Urb_fstnz, int_t *Ucbs,
int **ToSendR, int *ToSendD, int *ToRecv);
void allocBcastArray(void **array, int_t size, int root, MPI_Comm comm);

void bcastPermutedSparseA(SuperMatrix *A,
void dbcastPermutedSparseA(SuperMatrix *A,
dScalePermstruct_t *ScalePermstruct,
Glu_freeable_t *Glu_freeable,
dLUstruct_t *LUstruct, gridinfo3d_t *grid3d);


int_t* create_iperm_c_supno(int_t nsupers, superlu_dist_options_t *options, dLUstruct_t *LUstruct, gridinfo3d_t *grid3d);
gEtreeInfo_t fillEtreeInfo( int_t nsupers, int_t* setree, treeList_t *treeList);
void newTrfPartitionInit(int_t nsupers, dLUstruct_t *LUstruct, gridinfo3d_t *grid3d);
void dnewTrfPartitionInit(int_t nsupers, dLUstruct_t *LUstruct, gridinfo3d_t *grid3d);


int compareInt_t(void *a, void *b);
Expand Down
6 changes: 1 addition & 5 deletions SRC/include/superlu_ddefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,7 @@ typedef struct
double * Uval_buf ;
} dLUValSubBuf_t;

typedef enum {
NOT_IN_GRID, // doesn't belong to my grid
IN_GRID_ZERO, // belongsto my grid but doesn't initialized with zeros
IN_GRID_AIJ // belongsto my grid and initialized with non-zeros
} SupernodeToGridMap_t;




Expand Down
12 changes: 12 additions & 0 deletions SRC/include/superlu_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,11 @@ extern void C_BcTree_forwardMessageSimple(C_Tree* tree, void* localBuffer, int m
extern void C_BcTree_waitSendRequest(C_Tree* tree);

/*==== For 3D code ====*/
typedef enum {
NOT_IN_GRID, // doesn't belong to my grid
IN_GRID_ZERO, // belongsto my grid but doesn't initialized with zeros
IN_GRID_AIJ // belongsto my grid and initialized with non-zeros
} SupernodeToGridMap_t;

extern void DistPrint(char* function_name, double value, char* Units, gridinfo_t* grid);
extern void DistPrint3D(char* function_name, double value, char* Units, gridinfo3d_t* grid3d);
Expand All @@ -1282,6 +1287,13 @@ extern void permCol_SymbolicFact3d(superlu_dist_options_t *options, int_t n, Sup
Glu_persist_t *Glu_persist, Glu_freeable_t *Glu_freeable, SuperLUStat_t *stat,
superlu_dist_mem_usage_t*symb_mem_usage,
gridinfo3d_t* grid3d);
extern SupernodeToGridMap_t* createSuperGridMap(int_t nsuper,int_t maxLvl, int_t *myTreeIdxs,
int_t *myZeroTrIdxs, int_t* gNodeCount, int_t** gNodeLists);
extern int_t *createSupernode2TreeMap(int_t nsupers, int_t maxLvl, int_t *gNodeCount, int_t **gNodeLists);
extern void allocBcastArray(void **array, int_t size, int root, MPI_Comm comm);
extern int_t* create_iperm_c_supno(int_t nsupers, superlu_dist_options_t *options, Glu_persist_t *Glu_persist, int_t *etree, int_t** Lrowind_bc_ptr, int_t** Ufstnz_br_ptr, gridinfo3d_t *grid3d);
extern gEtreeInfo_t fillEtreeInfo( int_t nsupers, int_t* setree, treeList_t *treeList);
extern sForest_t **compute_sForests(int_t nsupers, Glu_persist_t *Glu_persist, int_t *etree, gridinfo3d_t *grid3d);

// 3D SpTRSV
typedef enum trtype_t {UPPER_TRI, LOWER_TRI} trtype_t;
Expand Down
Loading

0 comments on commit fb8cb39

Please sign in to comment.