Changeset 2eac950


Ignore:
Timestamp:
06/22/11 16:37:50 (2 years ago)
Author:
Oleg Batrashev <ogbash@…>
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)
Message:

Run PCG from Python.

Location:
src/ext
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • src/ext/C/doug_ext.f90

    re991513 r2eac950  
    4040 
    4141! Allocate memory for Distribution class. 
    42 subroutine ext_Distribution_NewInit(D, input_type, nparts) 
     42subroutine ext_Distribution_Init(D, input_type, nparts) 
    4343  use Distribution_mod 
    4444  use Distribution_base_mod 
    4545  use globals 
    4646 
    47   type(Distribution),pointer :: D 
     47  type(Distribution),intent(inout) :: D 
    4848  integer, intent(in) :: input_type 
    4949  integer, intent(in) :: nparts 
    5050  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) 
     53end subroutine ext_Distribution_Init 
    5554 
    5655function ext_Distribution_Get_Nlf(D) result(nlf) 
  • src/ext/C/doug_ext.h

    re991513 r2eac950  
    66extern void alloc_spmtx_(void **A); 
    77extern void alloc_mesh_(void **M); 
     8extern double ext_vec_dot_(double *v, double *x, double *y, int *nlf); 
    89extern void ext_distribution_new_(void **D); 
    9 extern double ext_vec_dot_(double *v, double *x, double *y, int *nlf); 
     10extern void ext_distribution_init_(void *D, int *input_type, int *nparts); 
    1011extern int ext_distribution_get_nlf_(void *D); 
     12extern void ext_finepreconditioner_new_(void **FP, void *D); 
    1113extern void ext_pcg(void *D, double *xl, int nlf, void *FP); 
    12 extern void ext_finepreconditioner_new_(void **FP, void *D); 
    1314 
    1415#endif 
  • src/ext/C/main_aggr.c

    re991513 r2eac950  
    1111  int nparts=1; 
    1212  int init_type=1; 
     13  int input_type=3; 
    1314  int nlf, i; 
    1415 
    1516  ext_doug_init_(&init_type); // parallel 
    16   ext_distribution_newinit_(&D); 
     17  ext_distribution_new_(&D); 
     18  ext_distribution_init_(D, &input_type, &nparts); 
    1719  nlf = ext_distribution_get_nlf_(D); 
    1820  printf("Initialized, Distribution %x, nlf=%d\n", D, nlf); 
  • src/ext/Python/dougmodule.c

    re991513 r2eac950  
    22 
    33#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 } 
    174 
    185/* types */ 
     
    7966} 
    8067 
     68static int 
     69Distribution_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 
     88typedef struct { 
     89    PyObject_HEAD 
     90    /* Type-specific fields go here. */ 
     91    void *fObj; 
     92} FinePreconditioner; 
     93 
     94static PyTypeObject FinePreconditionerType = { 
     95    PyObject_HEAD_INIT(NULL) 
     96    0,                         /*ob_size*/ 
     97    "doug.FinePreconditioner",        /*tp_name*/ 
     98    sizeof(FinePreconditioner)    /*tp_basicsize*/ 
     99}; 
     100 
     101static PyMethodDef FinePreconditioner_methods[] = { 
     102    {NULL}  /* Sentinel */ 
     103}; 
     104 
     105static void 
     106FinePreconditioner_dealloc(FinePreconditioner* self) 
     107{ 
     108  printf("FP dealloc %x\n", self); 
     109  self->ob_type->tp_free((PyObject*)self); 
     110} 
     111 
     112static int 
     113FinePreconditioner_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 
    81126/* module methods */ 
     127 
     128/* init & finalize */  
     129 
     130static PyObject * 
     131doug_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 
     141static PyObject * 
     142doug_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} 
    82161 
    83162static PyMethodDef DougMethods[] = { 
    84163    {"init",  doug_init, METH_VARARGS, "Initialize DOUG."}, 
     164    {"pcg",  doug_pcg, METH_VARARGS, "Preconditioned Conjugate Gradient."}, 
    85165    {NULL, NULL, 0, NULL} /* Sentinel */ 
    86166}; 
     
    95175 
    96176    DistributionType.tp_new = Distribution_new; 
     177    DistributionType.tp_init = (initproc)Distribution_init; 
    97178    DistributionType.tp_dealloc = (destructor)Distribution_dealloc; 
    98179    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) 
    99188        return; 
    100189 
     
    103192    Py_INCREF(&DistributionType); 
    104193    PyModule_AddObject(m, "Distribution", (PyObject *)&DistributionType); 
     194    Py_INCREF(&FinePreconditionerType); 
     195    PyModule_AddObject(m, "FinePreconditioner", (PyObject *)&FinePreconditionerType); 
    105196} 
Note: See TracChangeset for help on using the changeset viewer.