cscd_utils.c

Several operations on CSCD.

Summary
cscd_utils.cSeveral operations on CSCD.
csc_dispatchDistribute a CSC to a CSCD
csc_cyclic_distributionDistribute the CSC cyclicaly.
csc_simple_distributionDistribute the CSC.
cscd_build_g2lConstruct global to local tabular containing local number of global columns if one column is local, and -owner if column is not local.
cscd_checksymCheck if the CSCD graph is symetric.
cscd_symgraphSymetrize the graph of the given CSCD.
cscd_symgraph_intSymetrize the graph of the given CSCD.
add_two_floatsAdds two integers.
keep_firstReturns first integer.
keep_lastReturns last integer.
get_maxReturns maximum value from two integers.
get_minReturns minimum value from two integers.
cscd_addlocalInterface to cscd_addlocal_int, for external usage.
Variables
cursor
cscd_addlocal_intAdd second cscd to first cscd into third cscd (unallocated) Only adds columns from the second CSCD which belongs to the first one.
cscd_redispatch_scotchRedistribute the columns to have first columns on first proc for Scotch
cscd_redispatchRedistribute the first cscd into a new one using dl2g.
cscd_redispatch_intRedistribute the first cscd into a new one using dl2g.
cscd2cscTransform a cscd to a csc.
cscd2csc_intTransform a cscd to a csc.
csc2cscdTransform a csc to a cscd.
cscd_noDiagRemoves diagonal elements from a CSCD.
cscd_savesave a distributed csc to disk.
cscd_loadLoads a distributed csc from disk.

csc_dispatch

void csc_dispatch(INT gN,
INT *gcolptr,
INT *grow,
FLOAT *gavals,
FLOAT *grhs,
INT *gperm,
INT *ginvp,
INT *lN,
INT **lcolptr,
INT **lrow,
FLOAT **lavals,
FLOAT **lrhs,
INT **lperm,
INT **loc2glob,
int dispatch,
MPI_Comm pastix_comm)

Distribute a CSC to a CSCD

Parameters

gNglobal number of columns
gcolptrglobal starting index of each column in grows ans gavals.
growsglobal rows of each element.
gavalsglobal values of each element.
gpermglobal permutation tabular.
ginvpglobal reverse permutation tabular.
lNlocal number of columns (output).
lcolptrstarting index of each local column (output).
lrowptrrow number of each local element (output).
lavalsvalues of each local element (output).
lrhslocal part of the right hand side (output).
lpermlocal part of the permutation tabular (output).
loc2globglobal numbers of local columns (before permutation).
dispatchchoose how to dispatch the csc
pastix_commPaStiX MPI communicator.

csc_cyclic_distribution

INT csc_cyclic_distribution(INT column,
INT columnnbr,
MPI_Comm pastix_comm)

Distribute the CSC cyclicaly.

Parameters

columncolumn number to distribute
columnnbrNumber of colmuns.
pastix_commPaStiX MPI communicator

Return

owner of the column (column%commSize)

csc_simple_distribution

INT csc_simple_distribution(INT column,
INT columnnbr,
MPI_Comm pastix_comm)

Distribute the CSC.  First columns are for first proc and so on.

Parameters

columncolumn number to distribute
columnnbrNumber of colmuns.
pastix_commPaStiX MPI communicator

Return

owner of the column (column*commSize/columnnbr)

cscd_build_g2l

int cscd_build_g2l(INT ncol,
INT *loc2glob,
MPI_Comm comm,
INT *gN,
INT **g2l)

Construct global to local tabular containing local number of global columns if one column is local, and -owner if column is not local.

For i in 0, gN g2l[i] = i local number if i is local g2l[i] = -p if p is the owner of the column i

Parameters

nNumber of local columns
colptrStarting index of each columns in ja
rowsRow of each element.
valuesValue of each element.
l2gglobal number of each local column.
correctFlag indicating if we can correct the symmetry.
dofNumber of degrees of freedom.
commMPI communicator

cscd_checksym

int cscd_checksym(INT n,
INT *colptr,
INT **rows,
FLOAT **values,
INT *l2g,
int correct,
int alloc,
int dof,
MPI_Comm comm)

Check if the CSCD graph is symetric.

For all local column C,

For all row R in the column C,

If the row number R correspond to a local column, We look in column R if we have the row number C.

Else, we verify the column R belong to one proc

We had (ROW, l2g(COL)) (Fortran numbering) to list of the couples to send to the owner.

If we are not allowed to correct the matrix, we check that we have a local symmetry and return EXIT_FAILURE if it was not good on one processor.

If Local symmetry is good, or we are allowed to correct the matrix, we exchange couples (J,I) that processors should have and we check that this couples are present.

Parameters

nNumber of local columns
colptrStarting index of each columns in ja
rowsRow of each element.
valuesValue of each element.
l2gglobal number of each local column.
correctFlag indicating if we can correct the symmetry.
allocindicate if allocation on CSC uses internal malloc.
dofNumber of degrees of freedom.
commMPI communicator

cscd_symgraph

int cscd_symgraph(INT n,
INT *ia,
INT *ja,
FLOAT *a,
INT *newn,
INT **newia,
INT **newja,
FLOAT **newa,
INT *l2g,
MPI_Comm comm)

Symetrize the graph of the given CSCD.

External function.

Parameters

nNumber of local columns
iaStarting index of each columns in ja and a
jaRow of each element.
aValues of each element.
newnNew number of local columns
newiaStarting index of each columns in newja and newa
newjaRow of each element.
newaValues of each element.
l2gglobal number of each local column.
commMPI communicator.

cscd_symgraph_int

int cscd_symgraph_int(INT n,
INT *ia,
INT *ja,
FLOAT *a,
INT *newn,
INT **newia,
INT **newja,
FLOAT **newa,
INT *l2g,
MPI_Comm comm,
int malloc_flag)

Symetrize the graph of the given CSCD.

Internal function.

Parameters

nNumber of local columns
iaStarting index of each columns in ja and a
jaRow of each element.
aValues of each element.
newnNew number of local columns
newiaStarting index of each columns in newja and newa
newjaRow of each element.
newaValues of each element.
l2gglobal number of each local column.
commMPI communicator.
malloc_flagflag to indicate if function call is intern to pastix or extern.

add_two_floats

FLOAT add_two_floats(FLOAT a,
FLOAT b)

Adds two integers.

Parameters : a - first integer b - second integer

Returns: a + b

keep_first

FLOAT keep_first(FLOAT a,
FLOAT b)

Returns first integer.

Parameters : a - first integer b - second integer

Returns: a

keep_last

FLOAT keep_last(FLOAT a,
FLOAT b)

Returns last integer.

Parameters : a - first integer b - second integer

Returns: b

get_max

FLOAT get_max(FLOAT a,
FLOAT b)

Returns maximum value from two integers.

Parameters : a - first integer b - second integer

Returns: MAX(a,b)

get_min

FLOAT get_min(FLOAT a,
FLOAT b)

Returns minimum value from two integers.

Parameters : a - first integer b - second integer

Returns: MIN(a,b)

cscd_addlocal

int cscd_addlocal(INT ,
INT * ia ,
INT * ja ,
FLOAT * ,
INT *l2g,
INT addn,
INT *addia,
INT *addja,
FLOAT *adda,
INT *addl2g,
INT *newn,
INT **newia,
INT **newja,
FLOAT **newa,
CSCD_OPERATIONS_t OP,
int dof)

Interface to cscd_addlocal_int, for external usage.  Add second cscd to first cscd into third cscd (unallocated) Only adds columns from the second CSCD which belongs to the first one.

Parameters

nFirst cscd size
iaFirst cscd starting index of each column in ja and a
jaRow of each element in first CSCD
avalue of each cscd in first CSCD (can be NULL)
l2glocal 2 global column numbers for first cscd
addnCSCD to add size
addiaCSCD to add starting index of each column in addja and adda
addjaRow of each element in second CSCD
addavalue of each cscd in second CSCD (can be NULL -> add 0)
addl2glocal 2 global column numbers for second cscd
newnnew cscd size (same as first)
newiaCSCD to add starting index of each column in newja and newwa
newjaRow of each element in third CSCD
newavalue of each cscd in third CSCD
OPOperation to manage common CSCD coefficients.
dofNumber of degrees of freedom.

Variables

cursor

INT cursor

cscd_addlocal_int

Add second cscd to first cscd into third cscd (unallocated) Only adds columns from the second CSCD which belongs to the first one.  All this work is localy done.

Parameters

nFirst cscd size
iaFirst cscd starting index of each column in ja and a
jaRow of each element in first CSCD
avalue of each cscd in first CSCD (can be NULL)
l2glocal 2 global column numbers for first cscd
addnCSCD to add size
addiaCSCD to add starting index of each column in addja and adda
addjaRow of each element in second CSCD
addavalue of each cscd in second CSCD (can be NULL -> add 0)
addl2glocal 2 global column numbers for second cscd
newnnew cscd size (same as first)
newiaCSCD to add starting index of each column in newja and newwa
newjaRow of each element in third CSCD
newavalue of each cscd in third CSCD
add_fctFonction indicating what to do if a coefficient is in the two cscd.
dofNumber of degrees of freedom.
malloc_flagflag to indicate if function call is intern to pastix or extern.

cscd_redispatch_scotch

int cscd_redispatch_scotch(INT n,
INT *ia,
INT *ja,
FLOAT *a,
INT *l2g,
INT *dn,
INT **dia,
INT **dja,
FLOAT **da,
INT **dl2g,
MPI_Comm comm)

Redistribute the columns to have first columns on first proc for Scotch

  • Checks if the matrix is not allready well ditributed.
  • Build all new loc2globs on all processors.
  • Create new CSC for each processor and send it.
  • Merge all new CSC to the new local CSC with cscd_addlocal_int.

UNUSED

Parameters

nNumber of local columns
iaFirst cscd starting index of each column in ja and a
jaRow of each element in first CSCD
avalue of each cscd in first CSCD (can be NULL)
l2glocal 2 global column numbers for first cscd
dnNumber of local columns
diaFirst cscd starting index of each column in ja and a
djaRow of each element in first CSCD
davalue of each cscd in first CSCD (can be NULL)
l2glocal 2 global column numbers for first cscd
commMPI communicator

Returns

EXIT_SUCCESS if already well distributed, 2 if redistributed

cscd_redispatch

int cscd_redispatch(INT n,
INT *ia,
INT *ja,
FLOAT *a,
FLOAT *rhs,
INT *l2g,
INT dn,
INT **dia,
INT **dja,
FLOAT **da,
FLOAT **drhs,
INT *dl2g,
MPI_Comm comm)

Redistribute the first cscd into a new one using dl2g.

  • gather all new loc2globs on all processors.
  • allocate dia, dja and da.
  • Create new CSC for each processor and send it.
  • Merge all new CSC to the new local CSC with cscd_addlocal_int.

If communicator size is one, check that n = dn and l2g = dl2g and simply create a copy of the first cscd.

Parameters

nNumber of local columns
iaFirst cscd starting index of each column in ja and a
jaRow of each element in first CSCD
avalue of each cscd in first CSCD (can be NULL)
rhsright-hand-side member corresponding to the first CSCD (can be NULL)
l2glocal 2 global column numbers for first cscd
dnNumber of local columns
diaNew cscd starting index of each column in ja and a
djaRow of each element in new CSCD
davalue of each cscd in new CSCD
rhsright-hand-side member corresponding to the new CSCD
dl2glocal 2 global column numbers for new cscd
commMPI communicator

Returns

NO_ERRIf all goes well
BADPARAMETER_ERRIf commsize = 1 and n != dn or l2g != dl2g.

cscd_redispatch_int

int cscd_redispatch_int(INT n,
INT *ia,
INT *ja,
FLOAT *a,
FLOAT *rhs,
INT *l2g,
INT dn,
INT **dia,
INT **dja,
FLOAT **da,
FLOAT **drhs,
INT *dl2g,
int malloc_flag,
MPI_Comm comm)

Redistribute the first cscd into a new one using dl2g.

  • gather all new loc2globs on all processors.
  • allocate dia, dja and da.
  • Create new CSC for each processor and send it.
  • Merge all new CSC to the new local CSC with cscd_addlocal_int.

If communicator size is one, check that n = dn and l2g = dl2g and simply create a copy of the first cscd.

Suppose that values and rhs are NOT NULL, or NULL on all processors.  Thus, it doesn’t works if all matrix is on one pocessor and we want to distribute it with values...

Parameters

nNumber of local columns
iaFirst cscd starting index of each column in ja and a
jaRow of each element in first CSCD
avalue of each cscd in first CSCD (can be NULL)
rhsright-hand-side member corresponding to the first CSCD (can be NULL)
l2glocal 2 global column numbers for first cscd
dnNumber of local columns
diaNew cscd starting index of each column in ja and a
djaRow of each element in new CSCD
davalue of each cscd in new CSCD
rhsright-hand-side member corresponding to the new CSCD
dl2glocal 2 global column numbers for new cscd
malloc_flagInternal (API_YES) or external (API_NO) malloc use.
commMPI communicator

Returns

EXIT_SUCCESSIf all goes well
EXIT_FAILUREIf commsize = 1 and n != dn or l2g != dl2g.

cscd2csc

void cscd2csc(INT lN,
INT *lcolptr,
INT *lrow,
FLOAT *lavals,
FLOAT *lrhs,
INT *lperm,
INT *linvp,
INT *gN,
INT **gcolptr,
INT **grow,
FLOAT **gavals,
FLOAT **grhs,
INT **gperm,
INT **ginvp,
INT *loc2glob,
MPI_Comm pastix_comm)

Transform a cscd to a csc. colptr2, row2, avals2, rhs2, perm2, invp2 are allocated here.

External function, allocation are not of the internal type.

Parameters

lNnumber of local column.
lcolptrstarting index of each local column in row and avals. lrow _ row number of each local element.
lavalsvalues of each local element.
lrhslocal part of the right hand side.
lpermlocal part of the permutation tabular.
linvpMeans nothing, to suppress.
gNglobal number of columns (output).
gcolptrstarting index of each column in row2 and avals2 (output).
growrow number of each element (output).
gavalsvalues of each element (output).
grhsglobal right hand side (output).
gpermglobal permutation tabular (output).
ginvpglobal reverse permutation tabular (output).
loc2globglobal number of each local column.
pastix_commPaStiX MPI communicator.

cscd2csc_int

void cscd2csc_int(INT lN,
INT *lcolptr,
INT *lrow,
FLOAT *lavals,
FLOAT *lrhs,
INT *lperm,
INT *linvp,
INT *gN,
INT **gcolptr,
INT **grow,
FLOAT **gavals,
FLOAT **grhs,
INT **gperm,
INT **ginvp,
INT *loc2glob,
MPI_Comm pastix_comm,
int intern_flag)

Transform a cscd to a csc. colptr2, row2, avals2, rhs2, perm2, invp2 are allocated here.

Parameters

lNnumber of local column.
lcolptrstarting index of each local column in row and avals. lrow _ row number of each local element.
lavalsvalues of each local element.
lrhslocal part of the right hand side.
lpermlocal part of the permutation tabular.
linvpMeans nothing, to suppress.
gNglobal number of columns (output).
gcolptrstarting index of each column in row2 and avals2 (output).
growrow number of each element (output).
gavalsvalues of each element (output).
grhsglobal right hand side (output).
gpermglobal permutation tabular (output).
ginvpglobal reverse permutation tabular (output).
loc2globglobal number of each local column.
pastix_commPaStiX MPI communicator.
intern_flagDecide if malloc will use internal or external macros.

csc2cscd

void csc2cscd(INT gN,
INT *gcolptr,
INT *grow,
FLOAT *gavals,
FLOAT *grhs,
INT *gperm,
INT *ginvp,
INT lN,
INT **lcolptr,
INT **lrow,
FLOAT **lavals,
FLOAT **lrhs,
INT **lperm,
INT **linvp,
INT *loc2glob)

Transform a csc to a cscd.  Allocate the CSCD.  If grhs == NULL forget right hand side part.  If gperm == NULL forget permutation and reverse permutation part.

TODO: USE_EXTERNAL MALLOCS

Parameters

gNglobal number of columns
gcolptrglobal starting index of each column in grows ans gavals.
growsglobal rows of each element.
gavalsglobal values of each element.
gpermglobal permutation tabular.
ginvpglobal reverse permutation tabular.
lNlocal number of columns.
lcolptrstarting index of each local column.
lrowptrrow number of each local element.
lavalsvalues of each local element.
lrhslocal part of the right hand side (output).
lpermlocal part of the permutation tabular (output).
linvplocal part of the reverse permutation tabular (output).
loc2globglobal numbers of local columns (before permutation).

cscd_noDiag

int cscd_noDiag(INT n,
INT *ia,
INT *ja,
FLOAT *a,
INT *l2g)

Removes diagonal elements from a CSCD.  ja and a can be reallocated to ia[n]-1 elements after this call.

Parameters

nNumber of local columns
iaFirst cscd starting index of each column in ja and a
jaRow of each element in first CSCD
avalue of each cscd in first CSCD (can be NULL)
l2glocal 2 global column numbers for first cscd

cscd_save

int cscd_save(INT n,
INT *ia,
INT *ja,
FLOAT *a,
FLOAT *rhs,
INT *l2g,
int dof,
const char *filename,
MPI_Comm comm)

save a distributed csc to disk. files are called $(filename) and $(filename)$(RANK) if filename is NULL then filename = cscd_matrix.

file filename contains the number of processors/files on first line.  Then each line contain the name of each file (here $(filename)$(RANK)).

Parameters

nNumber of local columns
iaFirst cscd starting index of each column in ja and a
jaRow of each element in first CSCD
avalue of each cscd in first CSCD (can be NULL)
rhsRight hand side.
l2glocal 2 global column numbers for first cscd
dofNumber of degrees of freedom
filenamename of the files.
commMPI communicator

cscd_load

int cscd_load(INT *n,
INT **ia,
INT **ja,
FLOAT **a,
FLOAT **rhs,
INT **l2g,
const char *filename,
MPI_Comm mpi_comm)

Loads a distributed csc from disk. if filename is NULL then filename = cscd_matrix.

Parameters

nNumber of local columns
iaFirst cscd starting index of each column in ja and a
jaRow of each element in first CSCD
avalue of each cscd in first CSCD (can be NULL)
rhsRight hand side.
l2glocal 2 global column numbers for first cscd
filenamename of the files.
commMPI communicator
void csc_dispatch(INT gN,
INT *gcolptr,
INT *grow,
FLOAT *gavals,
FLOAT *grhs,
INT *gperm,
INT *ginvp,
INT *lN,
INT **lcolptr,
INT **lrow,
FLOAT **lavals,
FLOAT **lrhs,
INT **lperm,
INT **loc2glob,
int dispatch,
MPI_Comm pastix_comm)
Distribute a CSC to a CSCD
INT csc_cyclic_distribution(INT column,
INT columnnbr,
MPI_Comm pastix_comm)
Distribute the CSC cyclicaly.
INT csc_simple_distribution(INT column,
INT columnnbr,
MPI_Comm pastix_comm)
Distribute the CSC.
int cscd_build_g2l(INT ncol,
INT *loc2glob,
MPI_Comm comm,
INT *gN,
INT **g2l)
Construct global to local tabular containing local number of global columns if one column is local, and -owner if column is not local.
int cscd_checksym(INT n,
INT *colptr,
INT **rows,
FLOAT **values,
INT *l2g,
int correct,
int alloc,
int dof,
MPI_Comm comm)
Check if the CSCD graph is symetric.
int cscd_symgraph(INT n,
INT *ia,
INT *ja,
FLOAT *a,
INT *newn,
INT **newia,
INT **newja,
FLOAT **newa,
INT *l2g,
MPI_Comm comm)
Symetrize the graph of the given CSCD.
int cscd_symgraph_int(INT n,
INT *ia,
INT *ja,
FLOAT *a,
INT *newn,
INT **newia,
INT **newja,
FLOAT **newa,
INT *l2g,
MPI_Comm comm,
int malloc_flag)
Symetrize the graph of the given CSCD.
FLOAT add_two_floats(FLOAT a,
FLOAT b)
Adds two integers.
FLOAT keep_first(FLOAT a,
FLOAT b)
Returns first integer.
FLOAT keep_last(FLOAT a,
FLOAT b)
Returns last integer.
FLOAT get_max(FLOAT a,
FLOAT b)
Returns maximum value from two integers.
FLOAT get_min(FLOAT a,
FLOAT b)
Returns minimum value from two integers.
int cscd_addlocal(INT ,
INT * ia ,
INT * ja ,
FLOAT * ,
INT *l2g,
INT addn,
INT *addia,
INT *addja,
FLOAT *adda,
INT *addl2g,
INT *newn,
INT **newia,
INT **newja,
FLOAT **newa,
CSCD_OPERATIONS_t OP,
int dof)
Interface to cscd_addlocal_int, for external usage.
Add second cscd to first cscd into third cscd (unallocated) Only adds columns from the second CSCD which belongs to the first one.
INT cursor
int cscd_redispatch_scotch(INT n,
INT *ia,
INT *ja,
FLOAT *a,
INT *l2g,
INT *dn,
INT **dia,
INT **dja,
FLOAT **da,
INT **dl2g,
MPI_Comm comm)
Redistribute the columns to have first columns on first proc for Scotch
int cscd_redispatch(INT n,
INT *ia,
INT *ja,
FLOAT *a,
FLOAT *rhs,
INT *l2g,
INT dn,
INT **dia,
INT **dja,
FLOAT **da,
FLOAT **drhs,
INT *dl2g,
MPI_Comm comm)
Redistribute the first cscd into a new one using dl2g.
int cscd_redispatch_int(INT n,
INT *ia,
INT *ja,
FLOAT *a,
FLOAT *rhs,
INT *l2g,
INT dn,
INT **dia,
INT **dja,
FLOAT **da,
FLOAT **drhs,
INT *dl2g,
int malloc_flag,
MPI_Comm comm)
Redistribute the first cscd into a new one using dl2g.
void cscd2csc(INT lN,
INT *lcolptr,
INT *lrow,
FLOAT *lavals,
FLOAT *lrhs,
INT *lperm,
INT *linvp,
INT *gN,
INT **gcolptr,
INT **grow,
FLOAT **gavals,
FLOAT **grhs,
INT **gperm,
INT **ginvp,
INT *loc2glob,
MPI_Comm pastix_comm)
Transform a cscd to a csc.
void cscd2csc_int(INT lN,
INT *lcolptr,
INT *lrow,
FLOAT *lavals,
FLOAT *lrhs,
INT *lperm,
INT *linvp,
INT *gN,
INT **gcolptr,
INT **grow,
FLOAT **gavals,
FLOAT **grhs,
INT **gperm,
INT **ginvp,
INT *loc2glob,
MPI_Comm pastix_comm,
int intern_flag)
Transform a cscd to a csc.
void csc2cscd(INT gN,
INT *gcolptr,
INT *grow,
FLOAT *gavals,
FLOAT *grhs,
INT *gperm,
INT *ginvp,
INT lN,
INT **lcolptr,
INT **lrow,
FLOAT **lavals,
FLOAT **lrhs,
INT **lperm,
INT **linvp,
INT *loc2glob)
Transform a csc to a cscd.
int cscd_noDiag(INT n,
INT *ia,
INT *ja,
FLOAT *a,
INT *l2g)
Removes diagonal elements from a CSCD.
int cscd_save(INT n,
INT *ia,
INT *ja,
FLOAT *a,
FLOAT *rhs,
INT *l2g,
int dof,
const char *filename,
MPI_Comm comm)
save a distributed csc to disk.
int cscd_load(INT *n,
INT **ia,
INT **ja,
FLOAT **a,
FLOAT **rhs,
INT **l2g,
const char *filename,
MPI_Comm mpi_comm)
Loads a distributed csc from disk.
Close