Changeset 2eac950
- Timestamp:
- 06/22/11 16:37:50 (2 years ago)
- Branches:
- external
- Parents:
- e991513
- git-author:
- Oleg Batrashev <ogbash@…> (06/22/11 16:37:50)
- git-committer:
- Oleg Batrashev <ogbash@…> (06/22/11 16:37:50)
- Location:
- src/ext
- Files:
-
- 1 added
- 4 edited
-
C/doug_ext.f90 (modified) (1 diff)
-
C/doug_ext.h (modified) (1 diff)
-
C/main_aggr.c (modified) (1 diff)
-
Python/dougmodule.c (modified) (4 diffs)
-
Python/run.py (added)
Legend:
- Unmodified
- Added
- Removed
-
src/ext/C/doug_ext.f90
re991513 r2eac950 40 40 41 41 ! Allocate memory for Distribution class. 42 subroutine ext_Distribution_ NewInit(D, input_type, nparts)42 subroutine ext_Distribution_Init(D, input_type, nparts) 43 43 use Distribution_mod 44 44 use Distribution_base_mod 45 45 use globals 46 46 47 type(Distribution), pointer:: D47 type(Distribution),intent(inout) :: D 48 48 integer, intent(in) :: input_type 49 49 integer, intent(in) :: nparts 50 50 integer, dimension(6) :: part_opts 51 52 allocate(D) 53 D = Distribution_NewInit(sctls%input_type, nparts, part_opts) 54 end subroutine ext_Distribution_NewInit 51 52 D = Distribution_NewInit(input_type, nparts, part_opts) 53 end subroutine ext_Distribution_Init 55 54 56 55 function ext_Distribution_Get_Nlf(D) result(nlf) -
src/ext/C/doug_ext.h
re991513 r2eac950 6 6 extern void alloc_spmtx_(void **A); 7 7 extern void alloc_mesh_(void **M); 8 extern double ext_vec_dot_(double *v, double *x, double *y, int *nlf); 8 9 extern void ext_distribution_new_(void **D); 9 extern double ext_vec_dot_(double *v, double *x, double *y, int *nlf);10 extern void ext_distribution_init_(void *D, int *input_type, int *nparts); 10 11 extern int ext_distribution_get_nlf_(void *D); 12 extern void ext_finepreconditioner_new_(void **FP, void *D); 11 13 extern void ext_pcg(void *D, double *xl, int nlf, void *FP); 12 extern void ext_finepreconditioner_new_(void **FP, void *D);13 14 14 15 #endif -
src/ext/C/main_aggr.c
re991513 r2eac950 11 11 int nparts=1; 12 12 int init_type=1; 13 int input_type=3; 13 14 int nlf, i; 14 15 15 16 ext_doug_init_(&init_type); // parallel 16 ext_distribution_newinit_(&D); 17 ext_distribution_new_(&D); 18 ext_distribution_init_(D, &input_type, &nparts); 17 19 nlf = ext_distribution_get_nlf_(D); 18 20 printf("Initialized, Distribution %x, nlf=%d\n", D, nlf); -
src/ext/Python/dougmodule.c
re991513 r2eac950 2 2 3 3 #include "../C/doug_ext.h" 4 5 /* init & finalize */6 7 static PyObject *8 doug_init(PyObject *self, PyObject *args)9 {10 int init_type;11 12 if (!PyArg_ParseTuple(args, "i", &init_type))13 return NULL;14 ext_doug_init_(&init_type);15 Py_RETURN_NONE;16 }17 4 18 5 /* types */ … … 79 66 } 80 67 68 static int 69 Distribution_init(Distribution *self, PyObject *args, PyObject *kwds) 70 { 71 PyObject *tmp; 72 int input_type=0, nparts=1; 73 74 static char *kwlist[] = {"input_type", "nparts", NULL}; 75 76 if (! PyArg_ParseTupleAndKeywords(args, kwds, "i|i", kwlist, 77 &input_type, 78 &nparts)) 79 return -1; 80 81 ext_distribution_init_(self->fObj, &input_type, &nparts); 82 83 return 0; 84 } 85 86 // Fine Preconditioner 87 88 typedef struct { 89 PyObject_HEAD 90 /* Type-specific fields go here. */ 91 void *fObj; 92 } FinePreconditioner; 93 94 static PyTypeObject FinePreconditionerType = { 95 PyObject_HEAD_INIT(NULL) 96 0, /*ob_size*/ 97 "doug.FinePreconditioner", /*tp_name*/ 98 sizeof(FinePreconditioner) /*tp_basicsize*/ 99 }; 100 101 static PyMethodDef FinePreconditioner_methods[] = { 102 {NULL} /* Sentinel */ 103 }; 104 105 static void 106 FinePreconditioner_dealloc(FinePreconditioner* self) 107 { 108 printf("FP dealloc %x\n", self); 109 self->ob_type->tp_free((PyObject*)self); 110 } 111 112 static int 113 FinePreconditioner_init(FinePreconditioner *self, PyObject *args, PyObject *kwds) 114 { 115 Distribution *d; 116 int input_type=0, nparts=1; 117 118 if (!PyArg_ParseTuple(args, "O!", &DistributionType, &d)) 119 return -1; 120 121 ext_finepreconditioner_new_(&self->fObj, d->fObj); 122 123 return 0; 124 } 125 81 126 /* module methods */ 127 128 /* init & finalize */ 129 130 static PyObject * 131 doug_init(PyObject *self, PyObject *args) 132 { 133 int init_type; 134 135 if (!PyArg_ParseTuple(args, "i", &init_type)) 136 return NULL; 137 ext_doug_init_(&init_type); 138 Py_RETURN_NONE; 139 } 140 141 static PyObject * 142 doug_pcg(PyObject *self, PyObject *args) 143 { 144 Distribution *d; 145 FinePreconditioner *fp; 146 int nlf; 147 double *xl; 148 149 if (!PyArg_ParseTuple(args, "O!O!", &DistributionType, &d, 150 &FinePreconditionerType, &fp)) 151 return NULL; 152 153 nlf = ext_distribution_get_nlf_(d->fObj); 154 xl = malloc(nlf*sizeof(double)); 155 156 printf("nlf %d\n", nlf); 157 158 ext_pcg_(d->fObj, xl, &nlf, fp->fObj); 159 Py_RETURN_NONE; 160 } 82 161 83 162 static PyMethodDef DougMethods[] = { 84 163 {"init", doug_init, METH_VARARGS, "Initialize DOUG."}, 164 {"pcg", doug_pcg, METH_VARARGS, "Preconditioned Conjugate Gradient."}, 85 165 {NULL, NULL, 0, NULL} /* Sentinel */ 86 166 }; … … 95 175 96 176 DistributionType.tp_new = Distribution_new; 177 DistributionType.tp_init = (initproc)Distribution_init; 97 178 DistributionType.tp_dealloc = (destructor)Distribution_dealloc; 98 179 if (PyType_Ready(&DistributionType) < 0) 180 return; 181 182 FinePreconditionerType.tp_new = PyType_GenericNew; 183 FinePreconditionerType.tp_init = (initproc)FinePreconditioner_init; 184 FinePreconditionerType.tp_dealloc = (destructor)FinePreconditioner_dealloc; 185 FinePreconditionerType.tp_flags = Py_TPFLAGS_DEFAULT; 186 FinePreconditionerType.tp_doc = "FinePreconditioner objects"; 187 if (PyType_Ready(&FinePreconditionerType) < 0) 99 188 return; 100 189 … … 103 192 Py_INCREF(&DistributionType); 104 193 PyModule_AddObject(m, "Distribution", (PyObject *)&DistributionType); 194 Py_INCREF(&FinePreconditionerType); 195 PyModule_AddObject(m, "FinePreconditioner", (PyObject *)&FinePreconditionerType); 105 196 }
Note: See TracChangeset
for help on using the changeset viewer.
