/*----------------------------------------------------------------------------------*/ /* Parallel Sparse BLAS v 3.5.0 */ /* (C) Copyright 2017 Salvatore Filippone */ /* */ /* 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. The discretization ensures there are IDIM */ /* *internal* points in each direction. */ /* */ /*----------------------------------------------------------------------------------*/ #include #include #include #include #include "psb_base_cbind.h" #include "psb_prec_cbind.h" #include "psb_krylov_cbind.h" #define LINEBUFSIZE 1024 #define NBMAX 20 #define DUMPMATRIX 0 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(1.0/sqrt(3.0)); } double b2(double x, double y, double z) { return(1.0/sqrt(3.0)); } double b3(double x, double y, double z) { return(1.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); } } int matgen(int ictxt, int ng,int idim,int vg[],psb_c_dspmat *ah,psb_c_descriptor *cdh, psb_c_dvector *xh, psb_c_dvector *bh, psb_c_dvector *rh) { int iam, np; int ix, iy, iz, el,glob_row,i,info,ret; double x, y, z, deltah, sqdeltah, deltah2; double val[10*NBMAX], zt[NBMAX]; int irow[10*NBMAX], icol[10*NBMAX]; info = 0; psb_c_info(ictxt,&iam,&np); deltah = (double) 1.0/(idim+2); sqdeltah = deltah*deltah; deltah2 = 2.0* deltah; psb_c_set_index_base(0); for (glob_row=0; glob_row < ng; glob_row++) { /* Check if I have to do something about this entry */ if (vg[glob_row] == iam) { el=0; ix = glob_row/(idim*idim); iy = (glob_row-ix*idim*idim)/idim; iz = glob_row-ix*idim*idim-iy*idim; x=(ix+1)*deltah; y=(iy+1)*deltah; z=(iz+1)*deltah; zt[0] = 0.0; /* internal point: build discretization */ /* term depending on (x-1,y,z) */ val[el] = -a1(x,y,z)/sqdeltah-b1(x,y,z)/deltah2; if (ix==0) { zt[0] += g(0.0,y,z)*(-val[el]); } else { icol[el]=(ix-1)*idim*idim+(iy)*idim+(iz); el=el+1; } /* term depending on (x,y-1,z) */ val[el] = -a2(x,y,z)/sqdeltah-b2(x,y,z)/deltah2; if (iy==0) { zt[0] += g(x,0.0,z)*(-val[el]); } else { icol[el]=(ix)*idim*idim+(iy-1)*idim+(iz); el=el+1; } /* term depending on (x,y,z-1)*/ val[el]=-a3(x,y,z)/sqdeltah-b3(x,y,z)/deltah2; if (iz==0) { zt[0] += g(x,y,0.0)*(-val[el]); } else { icol[el]=(ix)*idim*idim+(iy)*idim+(iz-1); el=el+1; } /* term depending on (x,y,z)*/ val[el]=2.0*(a1(x,y,z)+a2(x,y,z)+a3(x,y,z))/sqdeltah + c(x,y,z); icol[el]=(ix)*idim*idim+(iy)*idim+(iz); el=el+1; /* term depending on (x,y,z+1) */ val[el] = -a3(x,y,z)/sqdeltah+b3(x,y,z)/deltah2; if (iz==idim-1) { zt[0] += g(x,y,1.0)*(-val[el]); } else { icol[el]=(ix)*idim*idim+(iy)*idim+(iz+1); el=el+1; } /* term depending on (x,y+1,z) */ val[el] = -a2(x,y,z)/sqdeltah+b2(x,y,z)/deltah2; if (iy==idim-1) { zt[0] += g(x,1.0,z)*(-val[el]); } else { icol[el]=(ix)*idim*idim+(iy+1)*idim+(iz); el=el+1; } /* term depending on (x+1,y,z) */ val[el] = -a1(x,y,z)/sqdeltah+b1(x,y,z)/deltah2; if (ix==idim-1) { zt[0] += g(1.0,y,z)*(-val[el]); } else { icol[el]=(ix+1)*idim*idim+(iy)*idim+(iz); el=el+1; } for (i=0; idescriptor); /* Clean up object handles */ free(ph); free(xh); free(bh); free(ah); free(cdh); fprintf(stderr,"program completed successfully\n"); psb_c_barrier(ictxt); psb_c_exit(ictxt); }