added: support parallel petsc 3.2, potentially built with 64bit indices
git-svn-id: http://svn.sintef.no/trondheim/IFEM/trunk@1358 e10b68d5-8a6e-419e-a041-bce267b0401d
This commit is contained in:
parent
d169860cd2
commit
44b2bbd617
@ -17,6 +17,17 @@
|
||||
#include "ASMbase.h"
|
||||
#include "MPC.h"
|
||||
|
||||
#ifdef HAS_PETSC
|
||||
#include "petscversion.h"
|
||||
|
||||
#if PETSC_VERSION_MAJOR == 3 && PETSC_VERSION_MINOR >= 2
|
||||
#define PETSCMANGLE(x) &x
|
||||
#else
|
||||
#define PETSCMANGLE(x) x
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
SAMpatchPara::SAMpatchPara (const std::map<int,int>& g2ln)
|
||||
{
|
||||
@ -37,8 +48,8 @@ SAMpatchPara::SAMpatchPara (const std::map<int,int>& g2ln)
|
||||
SAMpatchPara::~SAMpatchPara ()
|
||||
{
|
||||
#ifdef PARALLEL_PETSC
|
||||
ISDestroy(iglob);
|
||||
ISDestroy(iloc);
|
||||
ISDestroy(PETSCMANGLE(iglob));
|
||||
ISDestroy(PETSCMANGLE(iloc));
|
||||
#endif
|
||||
LinAlgInit::decrefs();
|
||||
}
|
||||
@ -97,7 +108,7 @@ bool SAMpatchPara::getNoDofCouplings (int ifirst, int ilast,
|
||||
}
|
||||
|
||||
// Generate nnz for off-diagonal block
|
||||
IntVec l2g(ndof);
|
||||
std::vector<PetscInt> l2g(ndof);
|
||||
Vector nnz(ndof);
|
||||
for (i = 0; i < ndof; i++) {
|
||||
l2g[i] = meqn[i]-1;
|
||||
@ -121,7 +132,7 @@ bool SAMpatchPara::getNoDofCouplings (int ifirst, int ilast,
|
||||
o_nnz[i] = ceil(vec[i]);
|
||||
|
||||
VecRestoreArray(x,&vec);
|
||||
VecDestroy(x);
|
||||
VecDestroy(PETSCMANGLE(x));
|
||||
|
||||
#else
|
||||
this->SAM::getNoDofCouplings(d_nnz);
|
||||
@ -170,8 +181,13 @@ bool SAMpatchPara::assembleSystem (SystemVector& sysRHS,
|
||||
PETScVector* pvec = dynamic_cast<PETScVector*>(&sysRHS);
|
||||
if (!pvec) return false;
|
||||
|
||||
std::vector<PetscInt> L2g;
|
||||
L2g.resize(l2g.size());
|
||||
for (size_t i=0;i<l2g.size();++i)
|
||||
L2g[i] = l2g[i];
|
||||
|
||||
// Add contributions to SV (righthand side)
|
||||
VecSetValues(pvec->getVector(),eSv.size(),&l2g[0],&eSv[0],ADD_VALUES);
|
||||
VecSetValues(pvec->getVector(),eSv.size(),&L2g[0],&eSv[0],ADD_VALUES);
|
||||
|
||||
// Add contributions to reaction forces
|
||||
if (reactionForces)
|
||||
@ -227,8 +243,8 @@ bool SAMpatchPara::expandSolution (const SystemVector& solVec,
|
||||
VecScatterCreate(svec->getVector(),iglob,solution,iloc,&ctx);
|
||||
VecScatterBegin(ctx,svec->getVector(),solution,INSERT_VALUES,SCATTER_FORWARD);
|
||||
VecScatterEnd(ctx,svec->getVector(),solution,INSERT_VALUES,SCATTER_FORWARD);
|
||||
VecScatterDestroy(ctx);
|
||||
VecDestroy(solution);
|
||||
VecScatterDestroy(PETSCMANGLE(ctx));
|
||||
VecDestroy(PETSCMANGLE(solution));
|
||||
|
||||
return true;
|
||||
#else
|
||||
@ -487,12 +503,16 @@ bool SAMpatchPara::initSystemEquations ()
|
||||
|
||||
#ifdef PARALLEL_PETSC
|
||||
// Generate 0-based local-to-global dof mapping
|
||||
IntVec l2g(ndof);
|
||||
std::vector<PetscInt> l2g(ndof);
|
||||
for (i = 0; i < ndof; i++)
|
||||
l2g[i] = meqn[i]-1;
|
||||
|
||||
// Generate global and local index sets
|
||||
#if PETSC_VERSION_MAJOR == 3 && PETSC_VERSION_MINOR >= 2
|
||||
ISCreateGeneral(PETSC_COMM_WORLD,ndof,&l2g[0],PETSC_COPY_VALUES,&iglob);
|
||||
#else
|
||||
ISCreateGeneral(PETSC_COMM_WORLD,ndof,&l2g[0],&iglob);
|
||||
#endif
|
||||
ISCreateStride(PETSC_COMM_WORLD,ndof,0,1,&iloc);
|
||||
#endif
|
||||
|
||||
|
@ -232,7 +232,7 @@ static void assemPETSc (const Matrix& eM, Mat SM, PETScVector& SV,
|
||||
size_t nedof = meen.size();
|
||||
|
||||
// Convert meen to 0-based C array
|
||||
int* l2g = new int[nedof];
|
||||
PetscInt* l2g = new PetscInt[nedof];
|
||||
for (i = 0; i < nedof; i++)
|
||||
l2g[i] = meqn[meen[i]-1]-1;
|
||||
|
||||
@ -303,7 +303,7 @@ static void assemPETSc (const Matrix& eM, Mat SM, PETScVector& SV,
|
||||
size_t nedof = meen.size();
|
||||
|
||||
// Convert meen to 0-based C array
|
||||
int* l2g = new int[nedof];
|
||||
PetscInt* l2g = new PetscInt[nedof];
|
||||
for (i = 0; i < nedof; i++)
|
||||
l2g[i] = meen[i]-1;
|
||||
|
||||
@ -388,7 +388,7 @@ static void assemPETSc (const Matrix& eM, Mat SM, const std::vector<int>& meen,
|
||||
size_t nedof = meen.size();
|
||||
|
||||
// Convert meen to 0-based C array
|
||||
int* l2g = new int[nedof];
|
||||
PetscInt* l2g = new PetscInt[nedof];
|
||||
for (i = 0; i < nedof; i++)
|
||||
l2g[i] = meen[i]-1;
|
||||
|
||||
@ -454,8 +454,18 @@ void PETScMatrix::initAssembly (const SAM& sam)
|
||||
std::vector<int> d_nnz, o_nnz;
|
||||
|
||||
MatGetOwnershipRange(A,&ifirst,&ilast);
|
||||
if (sam.getNoDofCouplings(ifirst,ilast,d_nnz,o_nnz))
|
||||
MatMPIAIJSetPreallocation(A,PETSC_DEFAULT,&(d_nnz[0]),PETSC_DEFAULT,&(o_nnz[0]));
|
||||
if (sam.getNoDofCouplings(ifirst,ilast,d_nnz,o_nnz))
|
||||
{
|
||||
std::vector<PetscInt> d_Nnz;
|
||||
std::vector<PetscInt> o_Nnz;
|
||||
d_Nnz.resize(d_nnz.size());
|
||||
for (size_t i=0;i<d_nnz.size();++i)
|
||||
d_Nnz[i] = d_nnz[i];
|
||||
o_Nnz.resize(o_nnz.size());
|
||||
for (size_t i=0;i<o_nnz.size();++i)
|
||||
o_Nnz[i] = o_nnz[i];
|
||||
MatMPIAIJSetPreallocation(A,PETSC_DEFAULT,&(d_Nnz[0]),PETSC_DEFAULT,&(o_Nnz[0]));
|
||||
}
|
||||
else {
|
||||
const PetscInt maxdofc = sam.getMaxDofCouplings();
|
||||
MatMPIAIJSetPreallocation(A,maxdofc,PETSC_NULL,maxdofc,PETSC_NULL);
|
||||
@ -464,7 +474,11 @@ void PETScMatrix::initAssembly (const SAM& sam)
|
||||
std::vector<int> nnz;
|
||||
|
||||
if (sam.getNoDofCouplings(nnz)) {
|
||||
PetscInt* nnzPtr = &(nnz[0]);
|
||||
std::vector<PetscInt> Nnz;
|
||||
Nnz.resize(nnz.size());
|
||||
for (size_t i=0;i<nnz.size();++i)
|
||||
Nnz[i] = nnz[i];
|
||||
PetscInt* nnzPtr = &(Nnz[0]);
|
||||
MatSeqAIJSetPreallocation(A,PETSC_DEFAULT,nnzPtr);
|
||||
}
|
||||
else {
|
||||
|
Loading…
Reference in New Issue
Block a user