[petsc-users] I write the following program, it can converge with 4 processor, but can not converge with 2 , or 3 processor. Could you help me out

Matthew Knepley knepley at gmail.com
Fri Aug 16 07:34:00 CDT 2013


On Fri, Aug 16, 2013 at 7:32 AM, 丁老师 <ztdepyahoo at 163.com> wrote:

> thank you very much! could you please suggest me a robust preconditioner
> which is independent of the number of processor.
>

For generic problems, they do not exist. I suggest looking in the
literature for your specific problem, and then
trying to construct the best few choices in PETSc.

   Matt


>
> 在 2013-08-16 19:54:01,"Matthew Knepley" <knepley at gmail.com> 写道:
>
> On Fri, Aug 16, 2013 at 6:13 AM, 丁老师 <ztdepyahoo at 163.com> wrote:
>
> Its common for iterative solvers to converge differently for different PC.
> You are using block Jacobi-ILU
> which is different for different numbers of processes.
>
>    Matt
>
> /* Program usage:  mpiexec ex1 [-help] [all PETSc options] */
>>
>> static char help[] = "Basic vector routines.\n\n";
>>
>>
>> #include "petscksp.h"
>> #include "petscvec.h"
>>
>>
>>
>> int main(int argc,char **argv)
>> {
>>   int N=16;
>>
>>   int MyRank;
>>
>>    Mat A;
>>    PC Pc;
>>    KSP ksp;
>>    Vec b,x;
>>
>>  PetscInitialize(&argc,&argv,(char*)0,help);
>>   MPI_Comm_rank(MPI_COMM_WORLD,&MyRank);
>>
>>   MatCreate(PETSC_COMM_WORLD,&A);
>>   MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,N,N);
>>   MatSetFromOptions(A);
>>   MatMPIAIJSetPreallocation(A,5,PETSC_NULL,5,PETSC_NULL);
>>
>>   VecCreate(PETSC_COMM_WORLD,&b);
>>   VecSetSizes(b,PETSC_DECIDE,N);
>>   VecSetFromOptions(b);
>>   VecDuplicate(b,&x);
>> &n bsp;
>>   int row=0;
>>   int* col3;
>>   int* col4;
>>   int* col5;
>>   PetscMalloc(3*sizeof(PetscInt),&col3);
>>   PetscMalloc(4*sizeof(PetscInt),&col4);
>>   PetscMalloc(5*sizeof(PetscInt),&col5);
>>
>>   col3[0]=0;  col3[1]=1;  col3[2]=4;
>>  double
>> value3[3]={2.2916666666666665e+00,-1.1458333333333333e+00,-1.1458333333333333e+00};
>>  MatSetValues(A,1,&row,3,col3,value3,INSERT_VALUES);
>>
>>  row=1;
>>  col4[0]=0;  col4[1]=1;  col4[2]=2; col4[3]=5;
>>  double
>> value4[4]={-1.1458333333333333e+00,3.8020833333333330e+00,-1.2500000000000000e+00
>> ,-1.4062500000000000e+00};
>>   MatSetValues(A,1,&row,4,col4,value4,INSERT_VALUES);
>>
>>
>>   row=2;
>>  col4[0]=1;  col4[1]=2;  col4[2]=3; col4[3]=6;
>>  value4[0]=-1.2500000000000000e+00;
>>  value4[1]=3.8020833333333330e+00;
>>  value4[2]=-1.1458333333333333e+00 ;
>> &n bsp;value4[3]=-1.4062500000000000e+00;
>>   MatSetValues(A,1,&row,4,col4,value4,INSERT_VALUES);
>>
>>
>>    row=3;
>>   col3[0]=2;  col3[1]=3;  col3[2]=7;
>>  value3[0]=-1.1458333333333333e+00;
>>  value3[1]=2.2916666666666665e+00;
>>  value3[2]=-1.1458333333333333e+00;
>>  MatSetValues(A,1,&row,3,col3,value3,INSERT_VALUES);
>>
>>
>>   row=4;
>>  col4[0]=0;  col4[1]=4;  col4[2]=5; col4[3]=8;
>>  value4[0]=-1.1458333333333333e+00;
>>  value4[1]=3.8020833333333330e+00;
>>  value4[2]=-1.4062500000000000e+00;
>>  value4[3]=-1.2500000000000000e+00;
>>   MatSetValues(A,1,&row,4,col4,value4,INSERT_VALUES);
>>
>>    row=5;
>>  col5[0]=1;  col5[1]=4;  col5[2]=5; col5[3]=6; col5[4]=9;
>>  double value5[5];
>>  value5[0]=-1.4062500000000000e+00;
>>  value5[1]=-1.4062500000000000e+00;
>>  value5[2]=5 .9375000000000000e+00;
>>  value5[3]=-1.5625000000000000e+00 ;
>>  value5[4]=-1.5625000000000000e+00 ;
>>   MatSetValues(A,1,&row,5,col5,value5,INSERT_VALUES);
>>
>>
>>
>>   row=6;
>>  col5[0]=2;  col5[1]=5;  col5[2]=6; col5[3]=7; col5[4]=10;
>>  value5[0]=-1.4062500000000000e+00;
>>  value5[1]=-1.5625000000000000e+00;
>>  value5[2]=5.9375000000000000e+00;
>>  value5[3]=-1.4062500000000000e+00 ;
>>  value5[4]=-1.5625000000000000e+00 ;
>>   MatSetValues(A,1,&row,5,col5,value5,INSERT_VALUES);
>>
>>   row=7;
>>  col4[0]=3;  col4[1]=6;  col4[2]=7; col4[3]=11;
>>  value4[0]=-1.1458333333333333e+00;
>>  value4[1]=-1.4062500000000000e+00;
>>  value4[2]=3.8020833333333330e+00;
>>  value4[3]=-1.2500000000000000e+00;
>>   MatSetValues(A,1,&row,4,col4,value4,INSERT_VALUES);
>>
>>   row=8;
>>   col4[0]=4;  col4[1]=8;  col4[2]=9; col4[3]=12;
>>  value4[0]=-1.2500000000000000e+00;
>>  value4[1]=3.8020833333333330e+00;
>>  value4[2]=-1.4062500000000000e+00;
>>  value4[3]=-1.1458333333333333e+00;
>>   MatSetValues(A,1,&row,4,col4,value4,INSERT_VALUES);
>>
>>
>>    row=9;
>>  col5[0]=5;  col5[1]=8;  col5[2]=9; col5[3]=10; col5[4]=13;
>>  value5[0]=-1.5625000000000000e+00;
>>  value5[1]=-1.4062500000000000e+00;
>>  value5[2]=5.9375000000000000e+00;
>>  value5[3]=-1.5625000000000000e+00 ;
>>  value5[4]= -1.4062500000000000e+00;
>>   MatSetValues(A,1,&row,5,col5,value5,INSERT_VALUES);
>>
>>      row=10;
>>  col5[0]=6;  col5[1]=9;  col5[2]=10; col5[3]=11; col5[4]=14;
>>  value5[0]=-1.5625000000000000e+00;
>>  value5[1]=-1.5625000000000000e+00;
>>  value5[2]=5.93750000000000 00e+00;
>>  value5[3]=-1.4062500000000000e+00 ;
>>  value5[4]= -1.4062500000000000e+00;
>>   MatSetValues(A,1,&row,5,col5,value5,INSERT_VALUES);
>>
>>
>>   row=11;
>>  col4[0]=7;  col4[1]=10;  col4[2]=11; col4[3]=15;
>>  value4[0]=-1.2500000000000000e+00;
>>  value4[1]=-1.4062500000000000e+00;
>>  value4[2]=3.8020833333333330e+00;
>>  value4[3]=-1.1458333333333333e+00;
>>   MatSetValues(A,1,&row,4,col4,value4,INSERT_VALUES);
>>
>>
>>
>>
>>     row=12;
>>   col3[0]=8;  col3[1]=12;  col3[2]=13;
>>  value3[0]=-1.1458333333333333e+00;
>>  value3[1]=2.2916666666666665e+00;
>>  value3[2]=-1.1458333333333333e+00;
>>  MatSetValues(A,1,&row,3,col3,value3,INSERT_VALUES);
>>
>>
>>    row=13;
>>  col4[0]=9;  col4[1]=12;  col4[2]=13; col4[3]= 14;
>>  value4[0]=-1.4062500000000000e+00;
>>  value4[1]=-1.1458333333333333e+00;
>>  value4[2]=3.8020833333333330e+00;
>>  value4[3]=-1.2500000000000000e+00;
>>   MatSetValues(A,1,&row,4,col4,value4,INSERT_VALUES);
>>
>>
>>    row=14;
>>  col4[0]=10;  col4[1]=13;  col4[2]=14; col4[3]=15;
>>  value4[0]=-1.4062500000000000e+00;
>>  value4[1]=-1.2500000000000000e+00;
>>  value4[2]=3.8020833333333330e+00;
>>  value4[3]=-1.1458333333333333e+00;
>>   MatSetValues(A,1,&row,4,col4,value4,INSERT_VALUES);
>>
>>
>>
>>      row=15;
>>   col3[0]=11;  col3[1]=14;  col3[2]=15;
>>  value3[0]=-1.1458333333333333e+00;
>>  value3[1]=-1.1458333333333333e+00;
>>  value3[2]=2.2916666666666665e+00;
>>  MatSetValues(A,1,&row,3,col3,value3,INSERT_VALUES);
>>
>>
>> &n bsp;
>>   MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
>>   MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);
>>
>> //  MatView(A,PETSC_VIEWER_STDOUT_WORLD);
>>
>>
>>
>>   double val[16]={-7.6233779415782715e-04,
>> -3.0457072596705860e-04,
>> 3.0457072596705860e-04,
>> 7.6233779415782715e-04,
>> -4.4764543813290442e-03,
>> -1.6196451741044846e-03,
>> 1.6196451741044846e-03,
>> 4.4764543813290442e-03,
>> -1.9333475373837013e-02,
>> -5.4815619458573189e-03,
>> 5.4815619458573189e-03,
>> 1.9333475373837013e-02,
>> -8.4153777598326651e-02,
>> -1.2883385353962010e-02,
>> 1.2883385353962010e-02,
>> 8.4153777598326651e-02};
>>
>> int* col16;
>>   PetscMalloc(16*sizeof(PetscInt),&col16);
>>  for(int i=0;i<16;i++)
>>   col16[i]=i;
>>
>> VecSetValues(b,16,col16,val,INSERT_VALUES);
>>     VecAssemblyBegin(b);
>>     VecAssemblyEnd(b);
>> //
>>  &nbs p;   VecView(b,PETSC_VIEWER_STDOUT_WORLD);
>>
>>
>>   KSPCreate(PETSC_COMM_WORLD,&ksp);
>>   KSPSetOperators(ksp,A,A,SAME_NONZERO_PATTERN);
>>   KSPSetOperators(ksp,A,A,SAME_PRECONDITIONER);
>>   KSPSetInitialGuessNonzero(ksp,PETSC_FALSE);
>>
>>   KSPSetType(ksp,KSPBCGS);
>>  //  KSPSetType(ksp,KSPLSQR);
>>  //  KSPSetType(ksp,KSPFGMRES);
>>  // KSPSetType(ksp,KSPDGMRES);
>> //KSPSetType(ksp,KSPTCQMR);
>>  // KSPSetType(ksp,KSPPREONLY);
>>
>>   //KSPGetPC(ksp,&Pc);
>>  // PCSetType(Pc,PCJACOBI);
>>   KSPSetFromOptions(ksp);
>>   KSPSetTolerances(ksp,1.e-20,1.e-20,PETSC_DEFAULT,1000);
>>   KSPSolve(ksp,b,x);
>>
>>
>>   VecView(x,PETSC_VIEWER_STDOUT_WORLD);
>>
>>
>>   PetscFinalize();
>>   return 0;
>> }
>>
>>
>>
>>
>>
>
>
> --
> What most experimenters take for granted before they begin their
> experiments is infinitely more interesting than any results to which their
> experiments lead.
> -- Norbert Wiener
>
>
>
>


-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20130816/75858cfd/attachment-0001.html>


More information about the petsc-users mailing list