<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p style="margin-top:0;margin-bottom:0"><span style="font-family: Calibri, Helvetica, sans-serif, Helvetica, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 14.6667px;">Since mumps
and scalapack are already installed on my computer, I only ran ./configure with --download-superlu_dist . </span><br>
</p>
<p style="margin-top:0;margin-bottom:0"><span style="font-family: Calibri, Helvetica, sans-serif, Helvetica, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 14.6667px;">After everything
is done, I received the error: </span></p>
<p style="margin-top:0;margin-bottom:0"><span style="font-family: Calibri, Helvetica, sans-serif, Helvetica, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 14.6667px;"></p>
<p style="margin: 0px; font: 11px Menlo;"><span style="font-variant-ligatures: no-common-ligatures;">dyld: lazy symbol binding failed: Symbol not found: _MatSolverTypeRegister_SuperLU_DIST</span></p>
<p style="margin: 0px; font: 11px Menlo;"><span style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space">
</span>Referenced from: /Users/yaxiong/Downloads/petsc-3.9.4/arch-darwin-c-debug/lib/libpetsc.3.9.dylib</span></p>
<p style="margin: 0px; font: 11px Menlo;"><span style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space">
</span>Expected in: flat namespace</span></p>
<p style="margin: 0px; font: 11px Menlo; min-height: 13px;"><span style="font-variant-ligatures: no-common-ligatures;"></span><br>
</p>
<p style="margin: 0px; font: 11px Menlo;"><span style="font-variant-ligatures: no-common-ligatures;">dyld: Symbol not found: _MatSolverTypeRegister_SuperLU_DIST</span></p>
<p style="margin: 0px; font: 11px Menlo;"><span style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space">
</span>Referenced from: /Users/yaxiong/Downloads/petsc-3.9.4/arch-darwin-c-debug/lib/libpetsc.3.9.dylib</span></p>
<p style="margin: 0px; font: 11px Menlo;"><span style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space">
</span>Expected in: flat namespace</span></p>
<p style="margin: 0px; font: 11px Menlo; min-height: 13px;"><span style="font-variant-ligatures: no-common-ligatures;"></span><br>
</p>
<p style="margin: 0px; font: 11px Menlo;"><span style="font-variant-ligatures: no-common-ligatures;">[0]PETSC ERROR: ------------------------------------------------------------------------</span></p>
<p style="margin: 0px; font: 11px Menlo;"><span style="font-variant-ligatures: no-common-ligatures;">[0]PETSC ERROR: Caught signal number 5 TRAP</span></p>
<p style="margin: 0px; font: 11px Menlo;"><span style="font-variant-ligatures: no-common-ligatures;">[0]PETSC ERROR: Try option -start_in_debugger or -on_error_attach_debugger</span></p>
<p style="margin: 0px; font: 11px Menlo;"><span style="font-variant-ligatures: no-common-ligatures;">[0]PETSC ERROR: or see http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind</span></p>
<p style="margin: 0px; font: 11px Menlo;"><span style="font-variant-ligatures: no-common-ligatures;">[0]PETSC ERROR: or try http://valgrind.org on GNU/linux and Apple Mac OS X to find memory corruption errors</span></p>
<p style="margin: 0px; font: 11px Menlo;"><span style="font-variant-ligatures: no-common-ligatures;">[0]PETSC ERROR: likely location of problem given in stack below</span></p>
<p style="margin: 0px; font: 11px Menlo;"><span style="font-variant-ligatures: no-common-ligatures;">[0]PETSC ERROR: ---------------------<span class="Apple-converted-space">
</span>Stack Frames ------------------------------------</span></p>
<p style="margin: 0px; font: 11px Menlo;"><span style="font-variant-ligatures: no-common-ligatures;">[0]PETSC ERROR: Note: The EXACT line numbers in the stack are not available,</span></p>
<p style="margin: 0px; font: 11px Menlo;"><span style="font-variant-ligatures: no-common-ligatures;">[0]PETSC ERROR:
<span class="Apple-converted-space"> </span>INSTEAD the line number of the start of the function</span></p>
<p style="margin: 0px; font: 11px Menlo;"><span style="font-variant-ligatures: no-common-ligatures;">[0]PETSC ERROR:
<span class="Apple-converted-space"> </span>is given.</span></p>
<p style="margin: 0px; font: 11px Menlo;"><span style="font-variant-ligatures: no-common-ligatures;">[0]PETSC ERROR: [0] MatInitializePackage line 150 /Users/yaxiong/Downloads/petsc-3.9.4/src/mat/interface/dlregismat.c</span></p>
<p style="margin: 0px; font: 11px Menlo;"><span style="font-variant-ligatures: no-common-ligatures;">[0]PETSC ERROR: [0] MatCreate line 83 /Users/yaxiong/Downloads/petsc-3.9.4/src/mat/utils/gcreate.c</span></p>
<p style="margin: 0px; font: 11px Menlo; color: rgb(195, 55, 32);"><span style="font-variant-ligatures: no-common-ligatures;"><b>[0]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------</b></span></p>
<p style="margin: 0px; font: 11px Menlo;"><span style="font-variant-ligatures: no-common-ligatures;">[0]PETSC ERROR: Signal received</span></p>
<br>
</span>
<p></p>
<br>
<div style="color: rgb(0, 0, 0);">
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Smith, Barry F. <bsmith@mcs.anl.gov><br>
<b>Sent:</b> Tuesday, February 5, 2019 10:58 PM<br>
<b>To:</b> Yaxiong Chen<br>
<b>Cc:</b> petsc-users@mcs.anl.gov<br>
<b>Subject:</b> Re: [petsc-users] PETSC matrix assembling super slow</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText"><br>
Run ./configure with --download-superlu_dist --download-mumps --download-scalapack and the you can use either -pc_factor_mat_solver_type superlu_dist or -pc_factor_mat_solver_type mumps<br>
<br>
Good luck<br>
<br>
<br>
> On Feb 5, 2019, at 9:29 PM, Yaxiong Chen <chen2018@purdue.edu> wrote:<br>
> <br>
> > Also, I found the solving time is also shorter when I use the direct solver(0.432s vs 4.332 s ). Is this due the small scale of the system? When I have a very large (e.g., 100000*100000 ) system, can I expect iterative solver being faster?<br>
> <br>
> << It sounds like the default preconditioner is not working well on your problem. First run with -ksp_monitor -ksp_converged_reason to get an idea of how quickly <<the iterative solver is converging. If the number of iterations is high you are going to
need to change the preconditioner to get one that converges well for your <<problem. What mathematical models is your code implementing, this will help in determining what type of preconditioner to use.<br>
> <br>
> << Barry<br>
> <br>
> <br>
> It seems I can only work with Jacobi pre-conditioner. When I try LU or Cholesky ,I got the error :<br>
> [0]PETSC ERROR: See <a href="http://www.mcs.anl.gov/petsc/documentation/linearsolvertable.html" id="LPlnk54523" class="OWAAutoLink" previewremoved="true">
http://www.mcs.anl.gov/petsc/documentation/linearsolvertable.html</a> for possible LU and Cholesky solvers<br>
> [0]PETSC ERROR: Could not locate a solver package. Perhaps you must ./configure with --download-<package><br>
> [0]PETSC ERROR: See <a href="http://www.mcs.anl.gov/petsc/documentation/faq.html" id="LPlnk335377" class="OWAAutoLink" previewremoved="true">
http://www.mcs.anl.gov/petsc/documentation/faq.html</a> for trouble shooting.<br>
> [0]PETSC ERROR: Petsc Release Version 3.9.4, Sep, 11, 2018 <br>
> [0]PETSC ERROR: ./optimal_mechanical_part.hdc on a arch-darwin-c-debug named hidac.ecn.purdue.edu by chen2018 Tue Feb 5 22:19:08 2019<br>
> [0]PETSC ERROR: Configure options <br>
> [0]PETSC ERROR: #1 MatGetFactor() line 4328 in /Users/yaxiong/Downloads/petsc-3.9.4/src/mat/interface/matrix.c<br>
> [0]PETSC ERROR: #2 PCSetUp_Cholesky() line 86 in /Users/yaxiong/Downloads/petsc-3.9.4/src/ksp/pc/impls/factor/cholesky/cholesky.c<br>
> [0]PETSC ERROR: #3 PCSetUp() line 923 in /Users/yaxiong/Downloads/petsc-3.9.4/src/ksp/pc/interface/precon.c<br>
> [0]PETSC ERROR: #4 KSPSetUp() line 381 in /Users/yaxiong/Downloads/petsc-3.9.4/src/ksp/ksp/interface/itfunc.c<br>
> [0]PETSC ERROR: #5 KSPSolve() line 612 in /Users/yaxiong/Downloads/petsc-3.9.4/src/ksp/ksp/interface/itfunc.c<br>
> solve time 3.8589999999985025E-003<br>
> reason 0<br>
> It asks me to download the package. Do I want to run the command in the folder of PETSC? But I am not sure what the name of the package should be . I tried with ./configure --download-<PCLU> But it does not work.<br>
> <br>
> From: Smith, Barry F. <bsmith@mcs.anl.gov><br>
> Sent: Tuesday, February 5, 2019 1:18 PM<br>
> To: Yaxiong Chen<br>
> Cc: PETSc users list<br>
> Subject: Re: [petsc-users] PETSC matrix assembling super slow<br>
> <br>
> <br>
> <br>
> > On Feb 5, 2019, at 10:32 AM, Yaxiong Chen <chen2018@purdue.edu> wrote:<br>
> > <br>
> > Thanks Barry,<br>
> > I will explore how to partition for parallel computation later. But now I still have some confusion on the sequential operation.<br>
> > I compared PETSC and Mumps. In both case, the subroutine for generating elemental matrix is very similar. However, the difference is in the following step£º<br>
> > call MatSetValues(Amat,ne,idx,ne,idx,Ae,ADD_VALUES,ierr)<br>
> > In this step ,each element cost about 3~4 e-2 second.<br>
> > <br>
> > However, when I use mumps, I use the following code: <br>
> > preA(Aptr+1:Aptr+n*(n+1)/2) = pack(Ae, mask(1:n,1:n))<br>
> > Aptr = Aptr +n*(n+1)/2<br>
> > if (allocated(auxRHSe)) preRHS(idx) = preRHS(idx)+auxRHSe<br>
> > It just cost 10e-6~10e-5 second. For a 10000*10000 matrix, the assembling time for using PETSC is 300s while it cost 60s when using Mumps.<br>
> > For a 10000*10000 system,the Is there any way I can make it faster? <br>
> <br>
> As we keep saying the slowness of the matrix assembly is due to incorrect preallocation. Once you have the preallocation correct the speed should increase dramatically.<br>
> <br>
> > Also, I found the solving time is also shorter when I use the direct solver(0.432s vs 4.332 s ). Is this due the small scale of the system? When I have a very large (e.g., 100000*100000 ) system, can I expect iterative solver being faster?<br>
> <br>
> It sounds like the default preconditioner is not working well on your problem. First run with -ksp_monitor -ksp_converged_reason to get an idea of how quickly the iterative solver is converging. If the number of iterations is high you are going to need
to change the preconditioner to get one that converges well for your problem. What mathematical models is your code implementing, this will help in determining what type of preconditioner to use.<br>
> <br>
> Barry<br>
> <br>
> <br>
> > <br>
> > Thanks<br>
> > <br>
> > Yaxiong<br>
> > <br>
> > <br>
> > <br>
> > <br>
> > <br>
> > Yaxiong Chen, <br>
> > Ph.D. Student <br>
> > <br>
> > School of Mechanical Engineering, 3171 <br>
> > 585 Purdue Mall<br>
> > West Lafayette, IN 47907<br>
> > <br>
> > <br>
> > <br>
> > <br>
> > <br>
> > From: Smith, Barry F. <bsmith@mcs.anl.gov><br>
> > Sent: Monday, February 4, 2019 10:42 PM<br>
> > To: Yaxiong Chen<br>
> > Cc: PETSc users list<br>
> > Subject: Re: [petsc-users] PETSC matrix assembling super slow<br>
> > <br>
> > <br>
> > <br>
> > > On Feb 4, 2019, at 4:41 PM, Yaxiong Chen <chen2018@purdue.edu> wrote:<br>
> > > <br>
> > > Hi Barry,<br>
> > > <br>
> > > !===================================================<br>
> > > mystart =rank +1 ! rank starts from 0<br>
> > > do i=mystart,nelem,nproc ! nelem: total number of elements ; nproc :number of process
<br>
> > > call ptSystem%getElementalMAT(i, Ae, auxRHSe, idx) ! Generate elemental matrix Ae and corresponding global Idx<br>
> > > ne=size(idx) <br>
> > > idx=idx-1 !-1 since PETSC index starts from zero <br>
> > > if (allocated(auxRHSe)) call VecSetValues(bvec,ne,idx,auxRHSe,ADD_VALUES,ierr)
<br>
> > > call MatSetValues(Amat,ne,idx,ne,idx,Ae,ADD_VALUES,ierr) ! Add elemental RHS to global RHS<br>
> > > end do<br>
> > > !===================================================<br>
> > > Maybe this is where I am wrong. The way I use MPI is to let each core generate the elemental matrix in turn.<br>
> > <br>
> > This is very bad strategy because there is no data locality. <br>
> > <br>
> > > Which means I have one global matrix on each core and finally add them together. My case is similar to typical finite element method. But the problem is the Index is not continuous, in this case I don't know how I can partition the global matrix. Do you
have any suggestions or do you have any template which can show me how finite element method use PETSC?<br>
> > <br>
> > What you need to do is partition the elements across the processors (so that the each process has a contiguous subdomain of elements), The each process computes the element stiffness for "its elements". There really isn't a single PETSc example that manages
this all directly for finite elements because that is a rather involved process to do it so as to get good performance.<br>
> > <br>
> > Depending on how specialized your problem needs to be you might consider using one of the packages libMesh, MOOSE or deal.ii to manage the elements and element computations (they all use PETSc for the algebraic solvers) instead of doing it yourself;
it is an involved process to do it all your self.<br>
> > <br>
> > Barry<br>
> > <br>
> > > <br>
> > > Thanks<br>
> > > <br>
> > > Yaxiong<br>
> > > <br>
> > > <br>
> > > From: Smith, Barry F. <bsmith@mcs.anl.gov><br>
> > > Sent: Monday, February 4, 2019 5:21 PM<br>
> > > To: Yaxiong Chen<br>
> > > Cc: Mark Adams; PETSc users list<br>
> > > Subject: Re: [petsc-users] PETSC matrix assembling super slow<br>
> > > <br>
> > > <br>
> > > <br>
> > > > On Feb 4, 2019, at 3:17 PM, Yaxiong Chen via petsc-users <petsc-users@mcs.anl.gov> wrote:<br>
> > > > <br>
> > > > Hi Mark,<br>
> > > > Will the parameter MatMPIAIJSetPreallocation in influence the following part<br>
> > > > do i=mystart,nelem,nproc<br>
> > > > call ptSystem%getElementalMAT(i, Ae, auxRHSe, idx)<br>
> > > > ne=size(idx)<br>
> > > > idx=idx-1 !-1 since PETSC index starts from zero <br>
> > > > if (allocated(auxRHSe)) call VecSetValues(bvec,ne,idx,auxRHSe,ADD_VALUES,ierr)<br>
> > > > call MatSetValues(Amat,ne,idx,ne,idx,Ae,ADD_VALUES,ierr)<br>
> > > > end do<br>
> > > > I found this part will impede my assembling process. In my case ,the total DOF is 20800. I estimated the upper bound of number of nonzero entries in each row as 594. So I set f9 to be 20206 and f6 to be 10103 in the following command:<br>
> > > > call MatMPIAIJSetPreallocation(Amat,f9,PETSC_NULL_INTEGER,f6,PETSC_NULL_INTEGER, ierr)<br>
> > > > <br>
> > > > Running the code in sequential mode with -info I got the following information.And I can get the result even thought the assembling process is kind of slow(several times slower than using Mumps).<br>
> > > > [0] MatAssemblyBegin_MPIBAIJ(): Stash has 0 entries,uses 0 mallocs.<br>
> > > > [0] MatAssemblyBegin_MPIBAIJ(): Block-Stash has 0 entries, uses 0 mallocs.<br>
> > > > [0] MatAssemblyEnd_SeqBAIJ(): Matrix size: 20800 X 20800, block size 1; storage space: 13847 unneeded, 1030038 used<br>
> > > > [0] MatAssemblyEnd_SeqBAIJ(): Number of mallocs during MatSetValues is 62659<br>
> > > <br>
> > > <br>
> > > Something is very wrong. The number of mallocs should be zero if you have the correct preallocation. Are you calling MatZeroEntries() or some other Mat routine before you call MatSetValues() ?<br>
> > > <br>
> > > <br>
> > > > [0] MatAssemblyEnd_SeqBAIJ(): Most nonzeros blocks in any row is 70<br>
> > > > [0] MatCheckCompressedRow(): Found the ratio (num_zerorows 0)/(num_localrows 20800) < 0.6. Do not use CompressedRow routines.<br>
> > > > [0] PetscCommDuplicate(): Using internal PETSc communicator 4462889472 140509341618528<br>
> > > > [0] PetscCommDuplicate(): Using internal PETSc communicator 4462889472 140509341618528<br>
> > > > [0] PetscCommDuplicate(): Using internal PETSc communicator 4462889472 140509341618528<br>
> > > > [0] VecScatterCreate_Seq(): Special case: sequential copy<br>
> > > > [0] MatAssemblyEnd_SeqBAIJ(): Matrix size: 20800 X 0, block size 1; storage space: 104000 unneeded, 0 used<br>
> > > > [0] MatAssemblyEnd_SeqBAIJ(): Number of mallocs during MatSetValues is 0<br>
> > > > [0] MatAssemblyEnd_SeqBAIJ(): Most nonzeros blocks in any row is 0<br>
> > > > [0] MatCheckCompressedRow(): Found the ratio (num_zerorows 20800)/(num_localrows 20800) > 0.6. Use CompressedRow routines.<br>
> > > > aseembel time 282.54871800000001 <br>
> > > > [0] PetscCommDuplicate(): Using internal PETSc communicator 4462888960 140509341442256<br>
> > > > [0] PCSetUp(): Setting up PC for first time<br>
> > > > [0] PCSetUp(): Leaving PC with identical preconditioner since operator is unchanged<br>
> > > > [0] PCSetUp(): Leaving PC with identical preconditioner since operator is unchanged<br>
> > > > [0] PCSetUp(): Leaving PC with identical preconditioner since operator is unchanged<br>
> > > > [0] PCSetUp(): Leaving PC with identical preconditioner since operator is unchanged<br>
> > > > [0] PCSetUp(): Leaving PC with identical preconditioner since operator is unchanged<br>
> > > > [0] PCSetUp(): Leaving PC with identical preconditioner since operator is unchanged<br>
> > > > [0] PCSetUp(): Leaving PC with identical preconditioner since operator is unchanged<br>
> > > > <br>
> > > > However, when I use the parallel mode,I got the following information:<br>
> > > > [0] MatAssemblyBegin_MPIBAIJ(): Stash has 707965 entries,uses 6 mallocs.<br>
> > > <br>
> > > You have a lot of off-process MatSetValues(). That is one process is generating a lot of matrix entries that belong on another process. This is not desirable. Ideally each process will generate the matrix entries that belong to that process so only
a few matrix entries need to be transported to another process. How are you partitioning the mesh and how are you deciding which process computes which which entries in the matrix? All of this may be need to be revisited.<br>
> > > <br>
> > > Barry<br>
> > > <br>
> > > <br>
> > > <br>
> > > > [0] MatAssemblyBegin_MPIBAIJ(): Block-Stash has 0 entries, uses 0 mallocs.<br>
> > > > <br>
> > > > it seems it never went to call MatAssemblyEnd(Amat,MAT_FINAL_ASSEMBLY,ierr)<br>
> > > > Is there anything I am doing wrong?<br>
> > > > Thanks<br>
> > > > <br>
> > > > Yaxiong Chen, <br>
> > > > Ph.D. Student <br>
> > > > <br>
> > > > School of Mechanical Engineering, 3171 <br>
> > > > 585 Purdue Mall<br>
> > > > West Lafayette, IN 47907<br>
> > > > <br>
> > > > <br>
> > > > <br>
> > > > <br>
> > > > <br>
> > > > From: Mark Adams <mfadams@lbl.gov><br>
> > > > Sent: Tuesday, January 29, 2019 10:02 PM<br>
> > > > To: Yaxiong Chen; PETSc users list<br>
> > > > Subject: Re: [petsc-users] PETSC matrix assembling super slow<br>
> > > > <br>
> > > > Optimized is a configuration flag not a versions.<br>
> > > > <br>
> > > > You need to figure out your number of non-zeros per row of you global matrix, or a bound on it, and supply that in MatMPIAIJSetPreallocation. Otherwise it has to allocate and copy memory often.<br>
> > > > <br>
> > > > You could increase your f9 on a serial run and see what runs best and then move to parallel with a value in f6 of about 1/2 of f9.<br>
> > > > <br>
> > > > On Tue, Jan 29, 2019 at 9:13 PM Yaxiong Chen <chen2018@purdue.edu> wrote:<br>
> > > > Thanks Mark, <br>
> > > > I use PETSC 3.9.4, is this the optimized version you called?<br>
> > > > Actually f9 and f6 are from the PETSC example. I don't know how to set the value correctly so I commend them. The size of my elemental matrix may vary. For 2D problem, the size of elemental matrix can be 24*24 or 32*32 or some other sizes. And the
index is not continuous. In this case, the elemental matrix may interlace with each other in the global matrix, and I may have thousands of elemental matrix to be assembled. Does the preallocating suitable for this?<br>
> > > > <br>
> > > > Yaxiong Chen, <br>
> > > > Ph.D. Student <br>
> > > > <br>
> > > > School of Mechanical Engineering, 3171 <br>
> > > > 585 Purdue Mall<br>
> > > > West Lafayette, IN 47907<br>
> > > > <br>
> > > > <br>
> > > > <br>
> > > > <br>
> > > > <br>
> > > > From: Mark Adams <mfadams@lbl.gov><br>
> > > > Sent: Tuesday, January 29, 2019 8:25 PM<br>
> > > > To: Yaxiong Chen<br>
> > > > Cc: Song Gao; petsc-users@mcs.anl.gov<br>
> > > > Subject: Re: [petsc-users] PETSC matrix assembling super slow<br>
> > > > <br>
> > > > Slow assembly is often from not preallocating correctly. I am guessing that you are using Q1 element and f9==9, and thus the preallocation should be OK if this is a scalar problem on a regular grid and f6-==6 should be OK for the off processor allocation,
if my assumptions are correct.<br>
> > > > <br>
> > > > You can run with -info, which will tell you how many allocation were done in assembly. Make sure that it is small (eg, 0).<br>
> > > > <br>
> > > > I see you use f90 array stuff 'idx-1'. Compilers can sometimes do crazy things with seeming simple code. You could just do this manually if you can find anything else.<br>
> > > > <br>
> > > > And I trust you are running an optimized version of PETSc.<br>
> > > > <br>
> > > > <br>
> > > > On Tue, Jan 29, 2019 at 6:22 PM Yaxiong Chen via petsc-users <petsc-users@mcs.anl.gov> wrote:<br>
> > > > Hi Song,<br>
> > > > I don't quite understand how I can use this command. I don't partition the gloabl matrix. If I add my elemental matrix to the global system it will be like this. And in my parallel part, I use each core to generate the elemental matrix in turn. In this
case, I guess each core will be assigned the space for global matrix and finally be assembled.But according to the manual, it seems each core will store a part of the global matrix. Is the local submatrix in the MatMPIAIJSetPreallocation(Mat B,PetscInt d_nz,const
PetscInt d_nnz[],PetscInt o_nz,const PetscInto_nnz[])the same as my elemental matrix?
<br>
> > > > <pastedImage.png><br>
> > > > <br>
> > > > <br>
> > > > Thanks<br>
> > > > <br>
> > > > Yaxiong Chen, <br>
> > > > Ph.D. Student <br>
> > > > <br>
> > > > School of Mechanical Engineering, 3171 <br>
> > > > 585 Purdue Mall<br>
> > > > West Lafayette, IN 47907<br>
> > > > <br>
> > > > <br>
> > > > <br>
> > > > <br>
> > > > <br>
> > > > From: Song Gao <song.gao2@mail.mcgill.ca><br>
> > > > Sent: Tuesday, January 29, 2019 1:22 PM<br>
> > > > To: Yaxiong Chen<br>
> > > > Cc: Matthew Knepley; petsc-users@mcs.anl.gov<br>
> > > > Subject: Re: [petsc-users] PETSC matrix assembling super slow<br>
> > > > <br>
> > > > I think you would prefer to preallocate the matrix<br>
> > > > <br>
> > > > uncomment this line <br>
> > > > ! call MatMPIAIJSetPreallocation(Amat,f9,PETSC_NULL_INTEGER,f6,PETSC_NULL_INTEGER, ierr)<br>
> > > > <br>
> > > > <br>
> > > > <br>
> > > > Le mar. 29 janv. 2019, ¨¤ 12 h 40, Yaxiong Chen via petsc-users <petsc-users@mcs.anl.gov> a ¨¦crit :<br>
> > > > Hello,<br>
> > > > <br>
> > > > I have a 2D system which is assembled by each elemental matrix. Ae is my elemental matrix, auxRHSe(:) and RHSe(:) and corresponding right hand side, idx is the global index. My code is as follow, however ,the assembling rate is super slow(Marked red
in the code). I am not sure whether the assembling type is right or not. Since for each element, idx are not continuous numbers. Do you have any idea what is the better way to assemble the matrix?<br>
> > > > <br>
> > > > Thanks<br>
> > > > <br>
> > > > block<br>
> > > > PetscErrorCode ierr<br>
> > > > PetscMPIInt rank,nproc, mystart<br>
> > > > PetscInt nelem<br>
> > > > integer,allocatable ::info(:)<br>
> > > > real(wp), allocatable :: Ae(:,:), auxRHSe(:),RHSe(:)<br>
> > > > integer, allocatable :: idx(:)<br>
> > > > PetscScalar, pointer :: xx_v(:)<br>
> > > > <br>
> > > > PC prec<br>
> > > > PetscScalar :: val<br>
> > > > Vec xvec,bvec,uvec<br>
> > > > Mat Amat<br>
> > > > KSP ksp<br>
> > > > PetscViewer viewer<br>
> > > > PetscInt geq,j,k,ne,M,Istart,Iend<br>
> > > > PetscBool flg<br>
> > > > KSPConvergedReason reason<br>
> > > > Vec dummyVec, dummyVecs(1)<br>
> > > > MatNullSpace nullspace<br>
> > > > <br>
> > > > call PetscInitialize( PETSC_NULL_CHARACTER, ierr )<br>
> > > > <br>
> > > > if (ierr .ne. 0) then<br>
> > > > print*,'Unable to initialize PETSc'<br>
> > > > stop<br>
> > > > endif<br>
> > > > call MPI_Comm_size(PETSC_COMM_WORLD,nproc,ierr)<br>
> > > > call MPI_Comm_rank(PETSC_COMM_WORLD,rank,ierr)<br>
> > > > mystart=rank+1<br>
> > > > <br>
> > > > ! Parameter set<br>
> > > > info=ptsystem%getInitInfo()<br>
> > > > nelem = info(Info_EleMatNum)+info(Info_FixedDOFNum)+info(Info_NumConstrain)
<br>
> > > > print*,'nelem',nelem<br>
> > > > !-------------------------------------<br>
> > > > ! Create Matrix<br>
> > > > call MatCreate(PETSC_COMM_WORLD,Amat,ierr)<br>
> > > > call MatSetSizes( Amat,PETSC_DECIDE, PETSC_DECIDE, info(1), info(1), ierr )<br>
> > > > call MatSetType( Amat, MATMPIBAIJ, ierr )<br>
> > > > ! call MatMPIAIJSetPreallocation(Amat,f9,PETSC_NULL_INTEGER,f6,PETSC_NULL_INTEGER, ierr)<br>
> > > > call MatSetFromOptions( Amat, ierr )<br>
> > > > call MatSetUp( Amat, ierr )<br>
> > > > call MatGetOwnershipRange( Amat, Istart, Iend, ierr )<br>
> > > > <br>
> > > > xvec = tVec(0)<br>
> > > > call MatCreateVecs( Amat, PETSC_NULL_VEC, xvec, ierr )<br>
> > > > call VecSetFromOptions( xvec, ierr )<br>
> > > > call VecDuplicate( xvec, bvec, ierr )<br>
> > > > call VecDuplicate( xvec, uvec, ierr )<br>
> > > > <br>
> > > > t1 = MPI_WTime(); <br>
> > > > <br>
> > > > do i=mystart,nelem,nproc<br>
> > > > call ptSystem%getElementalMAT(i, Ae, auxRHSe, idx)<br>
> > > > ne=size(idx)<br>
> > > > if (allocated(auxRHSe)) call VecSetValues(bvec,ne,idx-1,auxRHSe,ADD_VALUES,ierr)<br>
> > > > call MatSetValues(Amat,ne,idx-1,ne,idx-1,Ae,ADD_VALUES,ierr)<br>
> > > > end do<br>
> > > > <br>
> > > > nelem = info(Info_EleRHSNum)<br>
> > > > mystart = rank+1<br>
> > > > <br>
> > > > do i = mystart, nelem, nproc <br>
> > > > call ptSystem%getElementalRHS(i, RHSe, idx)<br>
> > > > print*,'idx',idx<br>
> > > > ne=size(idx)<br>
> > > > if (allocated(RHSe)) call VecSetValues(bvec,ne,idx-1,RHSe,ADD_VALUES,ierr)<br>
> > > > end do <br>
> > > > call MatAssemblyBegin(Amat,MAT_FINAL_ASSEMBLY,ierr)<br>
> > > > call MatAssemblyEnd(Amat,MAT_FINAL_ASSEMBLY,ierr) ! this part is slow, the for loop above is done but here it may get stuck<br>
> > > > call VecAssemblyBegin(bvec,ierr) ! For a 2500 DOF system, assembling only takes over 2 seconds<br>
> > > > call VecAssemblyEnd(bvec,ierr) ! But for a 10000 DOF system , it gets stuck<br>
> > > > t2 = MPI_WTime(); <br>
> > > > print*,'assembeling time',t2-t1<br>
> > > > ! Solve<br>
> > > > call KSPCreate(PETSC_COMM_WORLD,ksp,ierr)<br>
> > > > ! Set operators. Here the matrix that defines the linear system<br>
> > > > ! also serves as the preconditioning matrix.<br>
> > > > call KSPSetOperators(ksp,Amat,Amat,ierr)<br>
> > > > call KSPSetFromOptions(ksp,ierr)<br>
> > > > ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<br>
> > > > ! Solve the linear system<br>
> > > > ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<br>
> > > > call KSPSetType(ksp,KSPCG,ierr)<br>
> > > > call KSPGetPC(ksp,prec,ierr)<br>
> > > > ! call KSPSetPCSide(ksp,PC_SYMMETRIC,ierr)<br>
> > > > call PCSetType(prec,PCJACOBI,ierr)<br>
> > > > call KSPSolve(ksp,bvec,xvec,ierr)<br>
> > > > call PetscFinalize(ierr)<br>
> > > > <br>
> > > > end block<br>
> > > > <br>
> > > > <br>
> > > > Yaxiong Chen, <br>
> > > > Ph.D. Student <br>
> > > > <br>
> > > > School of Mechanical Engineering, 3171 <br>
> > > > 585 Purdue Mall<br>
> > > > West Lafayette, IN 47907<br>
<br>
</div>
</span></font></div>
</div>
</div>
</body>
</html>