Commit 6849fead authored by Alexander Danilov's avatar Alexander Danilov

Tests: added pmesh_test000

Added simple proof-of-concept Mesh::Redistribute() test.

Initial box mesh is distributed in chess-board fashion shifting from one
process to another several times.

In case (np=2) also check that adding 1 layer of ghost cells will cover
the whole mesh.

Wiki page for this test:
https://github.com/INMOST-DEV/INMOST/wiki/5300-Chessboard-Redistribute
parent f0e5d009
add_subdirectory(solver_test000)
\ No newline at end of file
add_subdirectory(solver_test000)
add_subdirectory(pmesh_test000)
# vtk DataFile Version 3.0
file is written by INMOST
ASCII
DATASET UNSTRUCTURED_GRID
POINTS 64 double
0 0 0
0 0 1
0 0 2
0 0 3
0 1 0
0 1 1
0 1 2
0 1 3
0 2 0
0 2 1
0 2 2
0 2 3
0 3 0
0 3 1
0 3 2
0 3 3
1 0 0
1 0 1
1 0 2
1 0 3
1 1 0
1 1 1
1 1 2
1 1 3
1 2 0
1 2 1
1 2 2
1 2 3
1 3 0
1 3 1
1 3 2
1 3 3
2 0 0
2 0 1
2 0 2
2 0 3
2 1 0
2 1 1
2 1 2
2 1 3
2 2 0
2 2 1
2 2 2
2 2 3
2 3 0
2 3 1
2 3 2
2 3 3
3 0 0
3 0 1
3 0 2
3 0 3
3 1 0
3 1 1
3 1 2
3 1 3
3 2 0
3 2 1
3 2 2
3 2 3
3 3 0
3 3 1
3 3 2
3 3 3
CELLS 27 243
8 0 4 5 1 16 20 21 17 8 1 5 6 2 17 21 22 18 8 2
6 7 3 18 22 23 19 8 4 8 9 5 20 24 25 21 8 5 9 10
6 21 25 26 22 8 6 10 11 7 22 26 27 23 8 8 12 13 9 24
28 29 25 8 9 13 14 10 25 29 30 26 8 10 14 15 11 26 30 31
27 8 17 16 20 21 33 32 36 37 8 18 17 21 22 34 33 37 38 8
19 18 22 23 35 34 38 39 8 21 20 24 25 37 36 40 41 8 22 21
25 26 38 37 41 42 8 23 22 26 27 39 38 42 43 8 25 24 28 29
41 40 44 45 8 26 25 29 30 42 41 45 46 8 27 26 30 31 43 42
46 47 8 33 32 36 37 49 48 52 53 8 34 33 37 38 50 49 53 54
8 35 34 38 39 51 50 54 55 8 37 36 40 41 53 52 56 57 8 38
37 41 42 54 53 57 58 8 39 38 42 43 55 54 58 59 8 41 40 44
45 57 56 60 61 8 42 41 45 46 58 57 61 62 8 43 42 46 47 59
58 62 63
CELL_TYPES 27
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
project(pmesh_test000)
set(SOURCE main.cpp)
add_executable(pmesh_test000 ${SOURCE})
target_link_libraries(pmesh_test000 inmost)
if(USE_MPI)
message("linking pmesh_test000 with MPI")
target_link_libraries(pmesh_test000 ${MPI_LIBRARIES})
if(MPI_LINK_FLAGS)
set_target_properties(pmesh_test000 PROPERTIES LINK_FLAGS "${MPI_LINK_FLAGS}")
endif()
endif(USE_MPI)
if( USE_MPI AND EXISTS ${MPIEXEC} )
add_test(NAME pmesh_test000_parallel_np_2 COMMAND ${MPIEXEC} -np 2 $<TARGET_FILE:pmesh_test000> ${CMAKE_CURRENT_SOURCE_DIR}/3x3x3.vtk)
add_test(NAME pmesh_test000_parallel_np_3 COMMAND ${MPIEXEC} -np 3 $<TARGET_FILE:pmesh_test000> ${CMAKE_CURRENT_SOURCE_DIR}/3x3x3.vtk)
add_test(NAME pmesh_test000_parallel_np_4 COMMAND ${MPIEXEC} -np 4 $<TARGET_FILE:pmesh_test000> ${CMAKE_CURRENT_SOURCE_DIR}/3x3x3.vtk)
endif()
#include <cstdio>
#include <cmath>
#include "../../inmost.h"
using namespace INMOST;
int main(int argc,char ** argv)
{
int errors = 0;
Mesh::Initialize(&argc,&argv);
Mesh * m = new Mesh(); // Create an empty mesh
m->SetCommunicator(INMOST_MPI_COMM_WORLD); // Set the MPI communicator for the mesh
int rank = m->GetProcessorRank(), nproc = m->GetProcessorsNumber();
/* Expected serial mesh with IxJxK box grid, you can try different prime values, like 13x17x19 */
if( rank == 0 ) m->Load((argc>1)?argv[1]:"3x3x3.vtk");
int total = m->TotalNumberOf(CELL);
if( rank == 0 ) std::cout << "Total cells: " << total << std::endl;
// Generate GlobalID for cells
m->AssignGlobalID(CELL);
// Copy them in order to check later
Tag idcopy = m->CreateTag("ID_copy",DATA_INTEGER,CELL,NONE,1);
for(Mesh::iteratorCell it = m->BeginCell(); it != m->EndCell(); ++it)
{
it->Integer(idcopy) = it->GlobalID();
}
// Create Tag to verify RedistributeTag
Tag pccopy = m->CreateTag("PC_copy",DATA_INTEGER,CELL,NONE,1);
for(int permut = 0; permut < nproc; permut++)
{
// Redistribute mesh in chess-board fashion, shifting each time by one proccess
Tag redist = m->RedistributeTag();
for(Mesh::iteratorCell it = m->BeginCell(); it != m->EndCell(); ++it)
{
it->Integer(redist) = (it->GlobalID() + permut) % nproc;
it->Integer(pccopy) = it->Integer(redist);
}
m->Redistribute(); // Redistribute the mesh data
m->ReorderEmpty(CELL|FACE|EDGE|NODE); // Clean the data after reordring [optional]
// Report number of local cells
std::cout << "Permut: " << permut << ", proc: " << rank << ", cells: " << m->NumberOfCells() << std::endl;
// Check that GlobalID and RedistributeTag are preserved
for(Mesh::iteratorCell it = m->BeginCell(); it != m->EndCell(); ++it)
{
if( it->Integer(pccopy) != rank )
{
std::cout << "Permut: " << permut << ", proc: " << rank << ", cell: " << it->GlobalID() << ", pccopy: " << it->Integer(pccopy) << std::endl;
errors++;
}
if( it->Integer(idcopy) != it->GlobalID() )
{
std::cout << "Permut: " << permut << ", proc: " << rank << ", cell: " << it->GlobalID() << ", idcopy: " << it->Integer(idcopy) << std::endl;
errors++;
}
}
}
// Obtain 1 layer of ghost cells
m->ExchangeGhost(1,FACE);
std::cout << "Ghost: proc: " << rank << ", cells: " << m->NumberOfCells() << std::endl;
if( nproc == 2 ) // In case np=2 and simple box 3x3x3 these should cover the whole mesh, let's check that!
{
int mask[total];
for (int i=0; i<total; i++) mask[i] = 0;
for(Mesh::iteratorCell it = m->BeginCell(); it != m->EndCell(); ++it)
{
mask[it->GlobalID()]++;
}
for (int i=0; i<total; i++) if ( mask[i] != 1)
{
std::cout << "Check: proc: " << rank << ", cell: " << i << ((mask[i])? " duplicated" : " missing") << std::endl;
errors++;
}
}
delete m;
Mesh::Finalize();
return (errors)? -1 : 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment