/*----------------------------------------------------------------------------------*/ /* Parallel Sparse BLAS v2.2 */ /* (C) Copyright 2007 Salvatore Filippone University of Rome Tor Vergata */ /* */ /* Redistribution and use in source and binary forms, with or without */ /* modification, are permitted provided that the following conditions */ /* are met: */ /* 1. Redistributions of source code must retain the above copyright */ /* notice, this list of conditions and the following disclaimer. */ /* 2. Redistributions in binary form must reproduce the above copyright */ /* notice, this list of conditions, and the following disclaimer in the */ /* documentation and/or other materials provided with the distribution. */ /* 3. The name of the PSBLAS group or the names of its contributors may */ /* not be used to endorse or promote products derived from this */ /* software without specific written permission. */ /* */ /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */ /* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED */ /* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ /* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS */ /* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR */ /* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF */ /* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS */ /* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) */ /* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */ /* POSSIBILITY OF SUCH DAMAGE. */ /* */ /* */ /* File: ppdec.c */ /* */ /* Program: ppdec */ /* This sample program shows how to build and solve a sparse linear */ /* */ /* The program solves a linear system based on the partial differential */ /* equation */ /* */ /* */ /* */ /* The equation generated is */ /* */ /* b1 d d (u) b2 d d (u) a1 d (u)) a2 d (u))) */ /* - ------ - ------ + ----- + ------ + a3 u = 0 */ /* dx dx dy dy dx dy */ /* */ /* */ /* with Dirichlet boundary conditions on the unit cube */ /* */ /* 0<=x,y,z<=1 */ /* */ /* The equation is discretized with finite differences and uniform stepsize; */ /* the resulting discrete equation is */ /* */ /* ( u(x,y,z)(2b1+2b2+a1+a2)+u(x-1,y)(-b1-a1)+u(x,y-1)(-b2-a2)+ */ /* -u(x+1,y)b1-u(x,y+1)b2)*(1/h**2) */ /* */ /* Example adapted from: C.T.Kelley */ /* Iterative Methods for Linear and Nonlinear Equations */ /* SIAM 1995 */ /* */ /* */ /* In this sample program the index space of the discretized */ /* computational domain is first numbered sequentially in a standard way, */ /* then the corresponding vector is distributed according to an HPF BLOCK */ /* distribution directive. */ /* */ /* Boundary conditions are set in a very simple way, by adding */ /* equations of the form */ /* */ /* u(x,y) = rhs(x,y) */ /* */ /*----------------------------------------------------------------------------------*/ #include #include #include #include #include "psb_base_cbind.h" #include "amg_cbind.h" double a1(double x, double y, double z) { return(1.0/80.0); } double a2(double x, double y, double z) { return(1.0/80.0); } double a3(double x, double y, double z) { return(1.0/80.0); } double c(double x, double y, double z) { return(0.0); } double b1(double x, double y, double z) { return(0.0/sqrt(3.0)); } double b2(double x, double y, double z) { return(0.0/sqrt(3.0)); } double b3(double x, double y, double z) { return(0.0/sqrt(3.0)); } double g(double x, double y, double z) { if (x == 1.0) { return(1.0); } else if (x == 0.0) { return( exp(-y*y-z*z)); } else { return(0.0); } } #define NBMAX 20 psb_i_t matgen(psb_c_ctxt cctxt, psb_i_t nl, psb_i_t idim, psb_l_t vl[], psb_c_dspmat *ah,psb_c_descriptor *cdh, psb_c_dvector *xh, psb_c_dvector *bh, psb_c_dvector *rh) { psb_i_t iam, np; psb_l_t ix, iy, iz, el,glob_row; psb_i_t i, k, info,ret; double x, y, z, deltah, sqdeltah, deltah2; double val[10*NBMAX], zt[NBMAX]; psb_l_t irow[10*NBMAX], icol[10*NBMAX]; info = 0; psb_c_info(cctxt,&iam,&np); deltah = (double) 1.0/(idim+1); sqdeltah = deltah*deltah; deltah2 = 2.0* deltah; psb_c_set_index_base(0); for (i=0; idescriptor); /* Clean up object handles */ free(ph); free(xh); free(bh); free(ah); free(cdh); if (iam == 0) fprintf(stderr,"program completed successfully\n"); psb_c_barrier(*cctxt); psb_c_exit(*cctxt); free(cctxt); }