Ice Sheet System Model  4.18
Code documentation
Chaco.cpp
Go to the documentation of this file.
1 /*\file Chaco.c
2  *\brief: Chaco partitioner mex module
3  */
4 
5 #ifdef HAVE_CONFIG_H
6 #include "config.h"
7 #else
8 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
9 #endif
10 
11 #include "./Chaco.h"
12 
13 void ChacoUsage(void){/*{{{*/
14  _printf0_("\n");
15  _printf0_("Usage: [assgn] = Chaco(A,vwgts,ewgts,x,y,z,options,nparts,goal);\n");
16  _printf0_("\n");
17 }/*}}}*/
18 WRAPPER(Chaco_python){
19 
20  int i;
21  int nterms;
22 
23  /*Inputs: */
24  int nvtxs; /* number of vertices in graph */
25  int *start = NULL; /* start of edge list for each vertex */
26  int *adjacency = NULL; /* edge list data */
27  int *vwgts = NULL; /* weights for all vertices */
28  float *ewgts = NULL; /* weights for all edges */
29  float *x = NULL;
30  float *y = NULL;
31  float *z = NULL; /* coordinates for inertial method */
32  double options[10] = {1,1,0,0,1,1,50,0,0.001,7654321}; /* architecture and partitioning options */
33  double *in_options = NULL;
34  int npart;
35  double *goal = NULL; /* desired set sizes */
36 
37  #ifndef _HAVE_CHACO_ //only works if dakota library has been compiled in.
38  _error_("Chaco not available! Cannot carry out Chaco partitioning!");
39  #endif
40 
41  /*Boot module: */
42  MODULEBOOT();
43 
44  /*checks on arguments on the matlab side: */
45  CHECKARGUMENTS(NLHS,NRHS,&ChacoUsage);
46 
47  /*Fetch Data*/
48  FetchChacoData(&nvtxs,&adjacency,&start,&ewgts,A_IN,EWGTS_IN);
49  FetchData(&vwgts,&nterms,VWGTS_IN);
50  FetchData(&x,&nterms,X_IN);
51  FetchData(&y,&nterms,Y_IN);
52  FetchData(&z,&nterms,Z_IN);
53  FetchData(&in_options,&nterms,OPTNS_IN);
54  for (i=0;i<(nterms<10?nterms:10);i++) options[i]=in_options[i]; //copy in_options into default options
55  FetchData(&npart,NPARTS_IN);
56  //int * nparts=xNew<int>(1); nparts[0]=npart; //weird Chacox interface ain't it?
57  FetchData(&goal,&nterms,GOAL_IN);
58 
59  /*Allocate output: */
60  short* assignment = xNewZeroInit<short>(nvtxs);
61 
62  /*Call core: */
63  Chacox(nvtxs, start, adjacency, vwgts, ewgts, x, y, z, assignment, options,&npart, goal);
64 
65  /*Output data: */
66  WriteData(ASSGN_OUT,assignment,nvtxs);
67 
68  /*Free ressources:*/
69  xDelete<short>(assignment);
70  xDelete<double>(goal);
71  //xDelete<int>(nparts);
72  xDelete<float>(z);
73  xDelete<float>(y);
74  xDelete<float>(x);
75  xDelete<float>(ewgts);
76  xDelete<int>(vwgts);
77  xDelete<int>(adjacency);
78  xDelete<int>(start);
79 
80  /*end module: */
81  MODULEEND();
82 }
_printf0_
#define _printf0_(StreamArgs)
Definition: Print.h:29
WriteData
void WriteData(IssmPDouble **pmatrix, int *pnel, int *matrix, int M, int N)
Definition: WriteJavascriptData.cpp:16
NRHS
#define NRHS
Definition: BamgConvertMesh.h:52
Chacox
int Chacox(int nvtxs, int *start, int *adjacency, int *vwgts, float *ewgts, float *x, float *y, float *z, short *assignment, double options[10], int *nparts, double *goal)
Definition: Chacox.cpp:7
WRAPPER
WRAPPER(Chaco_python)
Definition: Chaco.cpp:18
Chaco.h
header file for Chaco module.
FetchData
void FetchData(char **pstring, char *stringin)
Definition: FetchJavascriptData.cpp:16
NLHS
#define NLHS
Definition: BamgConvertMesh.h:50
ChacoUsage
void ChacoUsage(void)
Definition: Chaco.cpp:13
_error_
#define _error_(StreamArgs)
Definition: exceptions.h:49
FetchChacoData
void FetchChacoData(int *pnvtxs, int **padjacency, int **pstart, float **pewgts, const mxArray *A_IN, const mxArray *EWGTS_IN)
Definition: FetchMatlabData.cpp:477