39 #include "petscversion.h"
43 namespace MultiRegions
55 const boost::weak_ptr<ExpList> &pExp,
56 const boost::shared_ptr<AssemblyMap> &pLocToGloMap)
60 PetscInitialize(0, NULL, NULL, NULL);
63 MatCreate(PETSC_COMM_WORLD, &
m_matrix);
72 const Array<OneD,const NekDouble> &pInput,
73 Array<OneD, NekDouble> &pOutput,
77 const int nHomDofs = pNumRows - pNumDir;
83 VecAssemblyBegin(
m_b);
91 KSPGetIterationNumber(
m_ksp, &its);
92 cout <<
"iterations = " << its << endl;
110 IS isGlobal, isLocal;
112 PETSC_COPY_VALUES, &isGlobal);
113 ISCreateStride (PETSC_COMM_SELF, nHomDofs, 0, 1, &isLocal);
116 VecCreate (PETSC_COMM_SELF, &
m_locVec);
124 ISDestroy(&isGlobal);
129 const Array<OneD, const int> &glo2uniMap,
130 const Array<OneD, const int> &glo2unique,
134 =
m_expList.lock()->GetSession()->GetComm();
136 const int nDirDofs = pLocToGloMap->GetNumGlobalDirBndCoeffs();
137 const int nHomDofs = glo2uniMap.num_elements() - nDirDofs;
138 const int nProc = vComm->GetSize();
139 const int rank = vComm->GetRank();
147 Array<OneD, int> localCounts(nProc, 0), localOffset(nProc, 0);
148 localCounts[rank] = nHomDofs;
151 for (n = 1; n < nProc; ++n)
153 localOffset[n] = localOffset[n-1] + localCounts[n-1];
156 int totHomDofs =
Vmath::Vsum(nProc, localCounts, 1);
157 vector<unsigned int> allUniIds(totHomDofs, 0);
159 for (n = 0; n < nHomDofs; ++n)
161 int gid = n + nDirDofs;
162 allUniIds[n + localOffset[rank]] = glo2uniMap[gid];
166 std::sort(allUniIds.begin(), allUniIds.end());
167 map<int,int> uniIdReorder;
169 for (cnt = n = 0; n < allUniIds.size(); ++n)
171 if (uniIdReorder.count(allUniIds[n]) > 0)
176 uniIdReorder[allUniIds[n]] = cnt++;
179 for (n = 0; n < nHomDofs; ++n)
181 int gid = n + nDirDofs;
182 int uniId = glo2uniMap[gid];
183 ASSERTL0(uniIdReorder.count(uniId) > 0,
"Error in ordering");
191 VecCreate (PETSC_COMM_WORLD, &
m_x);
193 VecSetFromOptions(
m_x);
197 MatCreate (PETSC_COMM_WORLD, &
m_matrix);
200 PETSC_DETERMINE, PETSC_DETERMINE);
207 KSPCreate(PETSC_COMM_WORLD, &
m_ksp);
209 m_ksp, tolerance, PETSC_DEFAULT, PETSC_DEFAULT, PETSC_DEFAULT);
210 KSPSetFromOptions(
m_ksp);
211 #if PETSC_VERSION_GE(3,5,0)