/*****************************************************************************
/
/ SPACE (SPArse Cholesky Elimination) Library: protos.h
/
/ author        J"urgen Schulze, University of Paderborn
/ created       99sep14
/
/ This file contains the prototypes of all non-static functions
/
******************************************************************************/

/* functions in lib/greg_pord.h */
int 	greg_pord(int, int, int *, int *, int *, int *, int *);

/* functions in lib/graph.c */
graph_t*	newGraph(int, int);
void		freeGraph(graph_t*);
void		printGraph(graph_t*);
void		randomizeGraph(graph_t*);
graph_t*	setupSubgraph(graph_t*, int*, int, int*);
graph_t*	setupGraphFromMtx(inputMtx_t*);
graph_t*	setupGridGraph(int, int, int);
int		connectedComponents(graph_t*);
graph_t*	compressGraph(graph_t*, int*);

/* functions in lib/gbisect.c */
gbisect_t*      newGbisect(graph_t*);
void            freeGbisect(gbisect_t*);
void		printGbisect(gbisect_t*);
void            checkSeparator(gbisect_t*);
void            constructSeparator(gbisect_t*, options_t*, timings_t*);
int		smoothBy2Layers(gbisect_t*, int*, int*, int, int);
void            smoothSeparator(gbisect_t*, options_t*);

/* functions in lib/ddcreate.c */
domdec_t*	newDomainDecomposition(int, int);
void		freeDomainDecomposition(domdec_t*);
void		printDomainDecomposition(domdec_t*);
void		checkDomainDecomposition(domdec_t*);
void		buildInitialDomains(graph_t*, int*, int*, int*);
void		mergeMultisecs(graph_t *G, int*, int*);
domdec_t*	initialDomainDecomposition(graph_t*, int*, int*, int*);
domdec_t*	constructDomainDecomposition(graph_t*, int*);
void		computePriorities(domdec_t*, int*, int*, int);
void		eliminateMultisecs(domdec_t*, int*, int*);
void		findIndMultisecs(domdec_t*, int*, int*);
domdec_t*	coarserDomainDecomposition(domdec_t*, int*);
void		shrinkDomainDecomposition(domdec_t*, int);

/* functions in lib/ddbisect.c */
void		checkDDSep(domdec_t*);
int		findPseudoPeripheralDomain(domdec_t*, int);
void		constructLevelSep(domdec_t*, int);
void		initialDDSep(domdec_t*);
void		updateB2W(bucket_t*, bucket_t*, domdec_t*, int, int*,
			int*, int*, int*);
void		updateW2B(bucket_t*, bucket_t*, domdec_t*, int, int*,
			int*, int*, int*);
void		improveDDSep(domdec_t*);

/* functions in lib/gbipart.c */
gbipart_t*      newBipartiteGraph(int, int, int);
void            freeBipartiteGraph(gbipart_t*);
void		printGbipart(gbipart_t*);
gbipart_t*      setupBipartiteGraph(graph_t*, int*, int, int, int*);
void            maximumMatching(gbipart_t*, int*);
void            maximumFlow(gbipart_t*, int*, int*);
void            DMviaMatching(gbipart_t*, int*, int*, int*);
void            DMviaFlow(gbipart_t*, int*, int*, int*, int*);

/* functions in lib/nestdiss.c */
nestdiss_t*	newNDnode(graph_t*, int*, int);
void		freeNDnode(nestdiss_t*);
nestdiss_t*	setupNDroot(graph_t*, int*);
void		splitNDnode(nestdiss_t*, options_t*, timings_t*);
void		buildNDtree(nestdiss_t*, options_t*, timings_t*);
void		freeNDtree(nestdiss_t*);

/* functions in lib/multisector.c */
multisector_t*	newMultisector(graph_t*);
void		freeMultisector(multisector_t*);
multisector_t*	trivialMultisector(graph_t*);
multisector_t*	constructMultisector(graph_t*, options_t*, timings_t*);
multisector_t*	extractMS2stage(nestdiss_t*);
multisector_t*	extractMSmultistage(nestdiss_t*);

/* functions in lib/gelim.c */
gelim_t*	newElimGraph(int, int);
void		freeElimGraph(gelim_t*);
void		printElimGraph(gelim_t*);
gelim_t*	setupElimGraph(graph_t*);
int		crunchElimGraph(gelim_t*);
void		buildElement(gelim_t *Gelim, int me);
void		updateAdjncy(gelim_t*, int*, int, int*, int*);
void		findIndNodes(gelim_t*, int*, int, int*, int*, int*, int*);
void		updateDegree(gelim_t*, int*, int, int*);
void		updateScore(gelim_t*, int*, int, int, int*);
elimtree_t*	extractElimTree(gelim_t*);

/* functions in lib/bucket.c */
bucket_t*       newBucket(int, int, int);
void            freeBucket(bucket_t*);
bucket_t*	setupBucket(int, int, int);
int             minBucket(bucket_t*);
void            insertBucket(bucket_t*, int, int);
void            removeBucket(bucket_t*, int);

/* functions in lib/minpriority.c */
minprior_t*	newMinPriority(int nvtx, int nstages);
void		freeMinPriority(minprior_t*);
minprior_t*	setupMinPriority(multisector_t*);
elimtree_t*	orderMinPriority(minprior_t*, options_t*, timings_t*);
void		eliminateStage(minprior_t*, int, int, timings_t*);
int		eliminateStep(minprior_t*, int, int);

/* functions in lib/tree.c */
elimtree_t*     newElimTree(int, int);
void            freeElimTree(elimtree_t*);
void            printElimTree(elimtree_t *);
int             firstPostorder(elimtree_t*);
int             firstPostorder2(elimtree_t*, int);
int             nextPostorder(elimtree_t*, int);
int		firstPreorder(elimtree_t*);
int		nextPreorder(elimtree_t*, int);
elimtree_t*     setupElimTree(graph_t*, int*, int*);
void            initFchSilbRoot(elimtree_t*);
void		permFromElimTree(elimtree_t*, int*);
elimtree_t*	expandElimTree(elimtree_t*, int*, int);
elimtree_t*	permuteElimTree(elimtree_t*, int*);
elimtree_t*     fundamentalFronts(elimtree_t*);
elimtree_t*     mergeFronts(elimtree_t*, int);
elimtree_t*     compressElimTree(elimtree_t*, int*, int);
int             justifyFronts(elimtree_t*);
int             nWorkspace(elimtree_t*);
int             nFactorIndices(elimtree_t*);
int             nFactorEntries(elimtree_t*);
FLOAT           nFactorOps(elimtree_t*);
void		subtreeFactorOps(elimtree_t*, FLOAT*);
FLOAT		nTriangularOps(elimtree_t*);

/* functions in lib/matrix.c */
inputMtx_t*	newInputMtx(int, int);
void 		freeInputMtx(inputMtx_t*);
void		printInputMtx(inputMtx_t*);
denseMtx_t*     newDenseMtx(workspace_t*, int);
void		freeDenseMtx(denseMtx_t*);
void		printDenseMtx(denseMtx_t*);
void		checkDenseMtx(denseMtx_t*);
workspace_t*	initWorkspaceForDenseMtx(int, int);
FLOAT*		getWorkspaceForDenseMtx(workspace_t*, int);
void		freeWorkspaceForDenseMtx(workspace_t*);
inputMtx_t*	setupInputMtxFromGraph(graph_t*);
inputMtx_t*	setupLaplaceMtx(int, int, int);
inputMtx_t* 	permuteInputMtx(inputMtx_t*, int*);

/* functions in lib/symbfac.c */
css_t*		newCSS(int, int, int);
void		freeCSS(css_t*);
css_t*		setupCSSFromGraph(graph_t*, int*, int*);
css_t*		setupCSSFromFrontSubscripts(frontsub_t*);
frontsub_t*	newFrontSubscripts(elimtree_t*);
void		freeFrontSubscripts(frontsub_t*);
void		printFrontSubscripts(frontsub_t*);
frontsub_t*	setupFrontSubscripts(elimtree_t*, inputMtx_t*);
factorMtx_t*	newFactorMtx(int);
void		freeFactorMtx(factorMtx_t*);
void		printFactorMtx(factorMtx_t*);
void		initFactorMtx(factorMtx_t *L, inputMtx_t*);
void		initFactorMtxNEW(factorMtx_t *L, inputMtx_t*);

/* functions in lib/numfac.c */
void		numfac(factorMtx_t *L, timings_t *cpus);
denseMtx_t*	setupFrontalMtx(workspace_t*, factorMtx_t*, int);
void		initLocalIndices(denseMtx_t*, int*, int*);
denseMtx_t*	extendedAdd(denseMtx_t*, denseMtx_t*, int*, int*);
denseMtx_t*	setupUpdateMtxFromFrontalMtx(denseMtx_t*, factorMtx_t*);

/* functions in lib/kernel.c */
denseMtx_t*	factorize1x1Kernel(denseMtx_t*, int);
denseMtx_t*	factorize2x2Kernel(denseMtx_t*, int);
denseMtx_t*	factorize3x3Kernel(denseMtx_t*, int);

/* functions in lib/triangular.c */
void		forwardSubst1x1(factorMtx_t*, FLOAT*);
void		backwardSubst1x1(factorMtx_t*, FLOAT*);
void		forwardSubst1x1NEW(factorMtx_t*, FLOAT*);
void		backwardSubst1x1NEW(factorMtx_t*, FLOAT*);

/* functions in lib/mapping.c */
mapping_t*	newMapping(elimtree_t*, int);
void		freeMapping(mapping_t*);
void		printMapping(mapping_t*);
void		listing(mapping_t*, int, int, int, FLOAT*, FLOAT*);
mapping_t*	setupMapping(elimtree_t*, int, int);
void		split(mapping_t*, int, int, int, int*, int*, FLOAT*, int);

/* functions in lib/interface.c */
elimtree_t*	SPACE_ordering(graph_t*, options_t*, timings_t*);
elimtree_t*	SPACE_transformElimTree(elimtree_t*, int);
factorMtx_t*	SPACE_symbFac(elimtree_t*, inputMtx_t*);
void		SPACE_numFac(factorMtx_t*, timings_t*);
void		SPACE_solveTriangular(factorMtx_t *L, FLOAT *rhs, FLOAT *xvec);
void		SPACE_solve(inputMtx_t*, FLOAT*, FLOAT*, options_t*,
			timings_t*);
void		SPACE_solveWithPerm(inputMtx_t*, int*, FLOAT*, FLOAT*,
			options_t*, timings_t*);
mapping_t*	SPACE_mapping(graph_t*, int*, options_t*, timings_t*);

/* functions in lib/sort.c */
void 		insertUpInts(int, int*);
void		insertUpIntsWithStaticIntKeys(int, int*, int*);
void		insertDownIntsWithStaticFloatKeys(int, int*, FLOAT*);
void 		insertUpFloatsWithIntKeys(int, FLOAT*, int*);
void 		qsortUpInts(int, int*, int*);
void 		qsortUpFloatsWithIntKeys(int, FLOAT*, int*, int*);
void		distributionCounting(int, int*, int*);

/* functions in lib/read.c */
graph_t*	readChacoGraph(char*);
inputMtx_t*	readHarwellBoeingMtx(char*);

/* functions in libPAR/topology.c */
topology_t*	newTopology(int);
void		freeTopology(topology_t*);
void		printTopology(topology_t*);
topology_t*	setupTopology(void);
void		recMapCube(topology_t*, int, int, int, int, int, int);
void		sendCube(topology_t*, void*, size_t, int);
size_t		recvCube(topology_t*, void*, size_t, int);
int             myrank(void);

/* functions in libPAR/mask.c */
mask_t*		newMask(int);
void		freeMask(mask_t*);
mask_t*		setupMask(int, int, int);

/* functions in libPAR/broadcast.c */
void		broadcastInputMtx(topology_t*, inputMtx_t**);
void		broadcastElimTree(topology_t*, elimtree_t**);
void		broadcastArray(topology_t*, char*, size_t);

/* functions in libPAR/buffer.c */
buffer_t*	newBuffer(size_t);
void		freeBuffer(buffer_t*);
buffer_t*	exchangeBuffer(topology_t*, buffer_t*, int);
buffer_t*	setupSymbFacBuffer(frontsub_t*, int*);
void		readoutSymbFacBuffer(buffer_t*, frontsub_t*, int*);
buffer_t*	setupNumFacBuffer(workspace_t*, mask_t*, int);
void		readoutNumFacBuffer(workspace_t*, buffer_t*, denseMtx_t**);
buffer_t*	setupTriangularBuffer(frontsub_t*, int*, FLOAT*);
void		readoutTriangularBuffer(buffer_t*, frontsub_t*, int*, FLOAT*);

/* functions in libPAR/symbfacPAR.c */
frontsub_t*	newFrontSubscriptsPAR(mask_t*, mapping_t*, elimtree_t*);
frontsub_t*	setupFrontSubscriptsPAR(topology_t*, mask_t*, mapping_t*,
			elimtree_t*, inputMtx_t*);
css_t*		setupCSSFromFrontSubscriptsPAR(mask_t*, mapping_t*,
			frontsub_t*);
void		initFactorMtxPAR(mask_t*, mapping_t*, factorMtx_t*,
			inputMtx_t*);

/* functions in libPAR/numfacPAR.c */
void		numfacPAR(topology_t*, mask_t*, mapping_t*, factorMtx_t*,
			 int msglvl, timings_t*);
denseMtx_t*	setupFrontalMtxPAR(mask_t*, int, workspace_t*, factorMtx_t*,
			int);
void		initLocalIndicesPAR(denseMtx_t*, int*, int*);
denseMtx_t*	extendedAddPAR(denseMtx_t*, denseMtx_t*, int*, int*);
denseMtx_t*	setupUpdateMtxFromFrontalMtxPAR(denseMtx_t*, factorMtx_t*);
denseMtx_t*	setupUpdateMtxFromBuffer(workspace_t*, FLOAT*);
void		splitDenseMtxColumnWise(denseMtx_t*, mask_t*, buffer_t*, int);
void		splitDenseMtxRowWise(denseMtx_t*, mask_t*, buffer_t*, int);

/* functions in libPAR/kernelPAR.c */
denseMtx_t*	factorize1x1KernelPAR(topology_t*, mask_t*, int, denseMtx_t*,
			frontsub_t*, timings_t*);
denseMtx_t*	factorize2x2KernelPAR(topology_t*, mask_t*, int, denseMtx_t*,
			frontsub_t*, timings_t*);
denseMtx_t*	factorize3x3KernelPAR(topology_t*, mask_t*, int, denseMtx_t*,
			frontsub_t*, timings_t*);

/* functions in libPAR/triangularPAR.c */
void		forwardSubst1x1PAR(topology_t*, mask_t*, mapping_t*,
			factorMtx_t*, FLOAT*, FLOAT*);
void		backwardSubst1x1PAR(topology_t*, mask_t*, mapping_t*,
			factorMtx_t*, FLOAT*);
void		forwardSubst1x1KernelPAR(topology_t*, mask_t*, int, int,
			factorMtx_t*, FLOAT*, FLOAT*);
void		backwardSubst1x1KernelPAR(topology_t*, mask_t*, int, int,
			factorMtx_t*, FLOAT*);
void		accumulateVector(topology_t*, mask_t*, mapping_t*,
			factorMtx_t*, FLOAT*);

/* functions in libPAR/interfacePAR.c */
topology_t*	SPACE_setupTopology(void);
mask_t*		SPACE_setupMask(topology_t*, int);
void		SPACE_cleanup(topology_t*, mask_t*);
factorMtx_t*	SPACE_symbFacPAR(topology_t*, mask_t*, mapping_t*, elimtree_t*,
			inputMtx_t*);
void		SPACE_numFacPAR(topology_t*, mask_t*, mapping_t*, factorMtx_t*,
			int msglvl, timings_t*);
void		SPACE_solveTriangularPAR(topology_t*, mask_t*, mapping_t*,
			factorMtx_t*, FLOAT*, FLOAT*);
void		SPACE_solveWithPermPAR(topology_t *top, mask_t *mask,
			 inputMtx_t *A, int *perm, FLOAT *rhs, FLOAT *xvec,
			 options_t *options, timings_t *cpus);

