handle 2 ranks case

This commit is contained in:
Joachim Schöberl 2019-02-08 22:12:00 +01:00
parent 8a165ef8f1
commit 9500f8d8f2
2 changed files with 51 additions and 22 deletions

View File

@ -1073,29 +1073,45 @@ namespace netgen
Array<idx_t> epart(ne), npart(nn);
idxtype nparts = MyMPI_GetNTasks(GetCommunicator())-1;
idxtype edgecut;
idxtype ncommon = 3;
METIS_PartMeshDual (&ne, &nn, &eptr[0], &eind[0], NULL, NULL, &ncommon, &nparts,
NULL, NULL,
&edgecut, &epart[0], &npart[0]);
/*
METIS_PartMeshNodal (&ne, &nn, &eptr[0], &eind[0], NULL, NULL, &nparts,
NULL, NULL,
&edgecut, &epart[0], &npart[0]);
*/
PrintMessage (3, "metis complete");
// cout << "done" << endl;
for (int i = 0; i < GetNE(); i++)
VolumeElement(i+1).SetPartition(epart[i] + 1);
for (int i = 0; i < GetNSE(); i++)
SurfaceElement(i+1).SetPartition(epart[i+GetNE()] + 1);
for (int i = 0; i < GetNSeg(); i++)
LineSegment(i+1).SetPartition(epart[i+GetNE()+GetNSE()] + 1);
if (nparts == 1)
{
for (int i = 0; i < GetNE(); i++)
VolumeElement(i+1).SetPartition(1);
for (int i = 0; i < GetNSE(); i++)
SurfaceElement(i+1).SetPartition(1);
for (int i = 0; i < GetNSeg(); i++)
LineSegment(i+1).SetPartition(1);
}
else
{
idxtype edgecut;
idxtype ncommon = 3;
METIS_PartMeshDual (&ne, &nn, &eptr[0], &eind[0], NULL, NULL, &ncommon, &nparts,
NULL, NULL,
&edgecut, &epart[0], &npart[0]);
/*
METIS_PartMeshNodal (&ne, &nn, &eptr[0], &eind[0], NULL, NULL, &nparts,
NULL, NULL,
&edgecut, &epart[0], &npart[0]);
*/
PrintMessage (3, "metis complete");
// cout << "done" << endl;
for (int i = 0; i < GetNE(); i++)
VolumeElement(i+1).SetPartition(epart[i] + 1);
for (int i = 0; i < GetNSE(); i++)
SurfaceElement(i+1).SetPartition(epart[i+GetNE()] + 1);
for (int i = 0; i < GetNSeg(); i++)
LineSegment(i+1).SetPartition(epart[i+GetNE()+GetNSE()] + 1);
}
// surface elements attached to volume elements
Array<bool, PointIndex::BASE> boundarypoints (GetNP());
boundarypoints = false;
@ -1370,6 +1386,19 @@ namespace netgen
Array<idx_t> epart(ne), npart(nn);
idxtype nparts = MyMPI_GetNTasks(GetCommunicator())-1;
if (nparts == 1)
{
for (int i = 0; i < GetNE(); i++)
VolumeElement(i+1).SetPartition(1);
for (int i = 0; i < GetNSE(); i++)
SurfaceElement(i+1).SetPartition(1);
for (int i = 0; i < GetNSeg(); i++)
LineSegment(i+1).SetPartition(1);
return;
}
idxtype edgecut;

View File

@ -525,8 +525,8 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
MPI_Comm comm = pycomm!=nullptr ? pycomm->comm : self->GetCommunicator();
self->SetCommunicator(comm);
if(MyMPI_GetNTasks(comm)==1) return self;
if(MyMPI_GetNTasks(comm)==2) throw NgException("Sorry, cannot handle communicators with NP=2!");
cout << " rank " << MyMPI_GetId(comm) << " of " << MyMPI_GetNTasks(comm) << " called Distribute " << endl;
// if(MyMPI_GetNTasks(comm)==2) throw NgException("Sorry, cannot handle communicators with NP=2!");
// cout << " rank " << MyMPI_GetId(comm) << " of " << MyMPI_GetNTasks(comm) << " called Distribute " << endl;
if(MyMPI_GetId(comm)==0) self->Distribute();
else self->SendRecvMesh();
return self;