Skip to content

Commit

Permalink
Merge pull request #113 from imadhammani/main
Browse files Browse the repository at this point in the history
XCore AdaptMesh: fixed bugs with asan library
  • Loading branch information
benoit128 authored Jul 30, 2024
2 parents 7bdc3b3 + 7ac4703 commit 37696c3
Show file tree
Hide file tree
Showing 12 changed files with 143 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Cassiopee/KCore/KCore/Connect/ngonTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ void K_CONNECT::reversi_connex(E_Int *pgs, E_Int *xpgs, E_Int npgs,

for (E_Int i = xpgs[K]; i < xpgs[K+1]; i++) {
E_Int nei = neighbours[i];
if (processed[nei] || nei == -1)
if (nei == -1 || processed[nei])
continue;

// get the shared edge between face K and face nei
Expand Down
12 changes: 7 additions & 5 deletions Cassiopee/XCore/XCore/AdaptMesh/AdaptMesh_AssignRefData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,19 @@ PyObject *K_XCORE::AdaptMesh_AssignRefData(PyObject *self, PyObject *args)

Mesh *M = (Mesh *)PyCapsule_GetPointer(MESH, "AdaptMesh");

//assert(M->cref == NULL);
//assert(M->fref == NULL);
XFREE(M->cref);

Int *ptr = NULL;
Int ret, nfld, size;
ret = K_NUMPY::getFromNumpyArray(CREF, M->cref, size, nfld, false);
ret = K_NUMPY::getFromNumpyArray(CREF, ptr, size, nfld, true);
if (ret != 1 || size != M->nc || nfld != 1) {
RAISE("Bad cref input.");
return NULL;
}

M->cref = (Int *)XRESIZE(M->cref, M->nc * sizeof(Int));
for (Int i = 0; i < M->nc; i++) M->cref[i] = ptr[i];

Py_DECREF(CREF);

// Allocate patch buffers

for (Int i = 0; i < M->npp; i++) {
Expand Down
72 changes: 69 additions & 3 deletions Cassiopee/XCore/XCore/AdaptMesh/AdaptMesh_ExtractData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ PyObject *K_XCORE::AdaptMesh_ExtractOwners(PyObject *self, PyObject *args)

Mesh *M = (Mesh *)PyCapsule_GetPointer(MESH, "AdaptMesh");

if (M->pid == 0) puts("Extracting owners...");
if (M->pid == 0) puts("Extracting face owners...");

npy_intp dims[2];

Expand All @@ -52,6 +52,39 @@ PyObject *K_XCORE::AdaptMesh_ExtractOwners(PyObject *self, PyObject *args)
return (PyObject *)OWN;
}

PyObject *K_XCORE::AdaptMesh_ExtractNeighbours(PyObject *self, PyObject *args)
{
PyObject *MESH;

if (!PYPARSETUPLE_(args, O_, &MESH)) {
RAISE("Wrong input.");
return NULL;
}

if (!PyCapsule_IsValid(MESH, "AdaptMesh")) {
RAISE("Bad mesh hook.");
return NULL;
}

Mesh *M = (Mesh *)PyCapsule_GetPointer(MESH, "AdaptMesh");

if (M->pid == 0) puts("Extracting face neighbours...");

npy_intp dims[2];

dims[1] = 1;
dims[0] = (npy_intp)M->nf;
PyArrayObject *NEI = (PyArrayObject *)PyArray_SimpleNew(1, dims, E_NPY_INT);

Int *pn = (Int *)PyArray_DATA(NEI);

for (Int i = 0; i < M->nf; i++) {
pn[i] = M->neigh[i];
}

return (PyObject *)NEI;
}

PyObject *K_XCORE::AdaptMesh_ExtractCellLevels(PyObject *self, PyObject *args)
{
PyObject *MESH;
Expand Down Expand Up @@ -86,7 +119,40 @@ PyObject *K_XCORE::AdaptMesh_ExtractCellLevels(PyObject *self, PyObject *args)
}


PyObject *K_XCORE::AdaptMesh_ExtractNeighbourCellLevels(PyObject *self, PyObject *args)
PyObject *K_XCORE::AdaptMesh_ExtractCellRanges(PyObject *self, PyObject *args)
{
PyObject *MESH;

if (!PYPARSETUPLE_(args, O_, &MESH)) {
RAISE("Wrong input.");
return NULL;
}

if (!PyCapsule_IsValid(MESH, "AdaptMesh")) {
RAISE("Bad mesh hook.");
return NULL;
}

Mesh *M = (Mesh *)PyCapsule_GetPointer(MESH, "AdaptMesh");

if (M->pid == 0) puts("Extracting cell ranges...");

PyObject *STR = K_NUMPY::buildNumpyArray(M->nc, 6, 1, 1);

Int *ptr = K_NUMPY::getNumpyPtrI(STR);

for (Int cid = 0; cid < M->nc; cid++) {
Int *crange = Mesh_get_crange(M, cid);

for (Int j = 0; j < M->cstride[cid]; j++) {
ptr[cid + j*M->nc] = crange[j];
}
}

return (PyObject *)STR;
}

PyObject *K_XCORE::AdaptMesh_ExtractHaloCellLevels(PyObject *self, PyObject *args)
{
PyObject *MESH;

Expand All @@ -102,7 +168,7 @@ PyObject *K_XCORE::AdaptMesh_ExtractNeighbourCellLevels(PyObject *self, PyObject

Mesh *M = (Mesh *)PyCapsule_GetPointer(MESH, "AdaptMesh");

if (M->pid == 0) puts("Extracting neighbour cell levels...");
if (M->pid == 0) puts("Extracting halo cell levels...");

// Allocate

Expand Down
20 changes: 16 additions & 4 deletions Cassiopee/XCore/XCore/AdaptMesh/AdaptMesh_Init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,12 @@ PyObject *K_XCORE::AdaptMesh_Init(PyObject *self, PyObject *args)
assert(PyList_Size(PATCH) == 4);

// TODO(Imad): error check
K_NUMPY::getFromNumpyArray(PyList_GetItem(PATCH, 0), M->bps[i].pf,
M->bps[i].nf, false);
Int *ptr = NULL;
K_NUMPY::getFromNumpyArray(PyList_GetItem(PATCH, 0), ptr,
M->bps[i].nf, true);

M->bps[i].pf = IntArray(M->bps[i].nf);
for (Int j = 0; j < M->bps[i].nf; j++) M->bps[i].pf[j] = ptr[j];

M->bps[i].gid = PyLong_AsLong(PyList_GetItem(PATCH, 1));

Expand Down Expand Up @@ -153,12 +157,20 @@ PyObject *K_XCORE::AdaptMesh_Init(PyObject *self, PyObject *args)
M->pps[i].nei = PyLong_AsLong(PyList_GetItem(PATCH, 0));

// TODO(Imad): error check
Int *ptr = NULL;
K_NUMPY::getFromNumpyArray(PyList_GetItem(PATCH, 1),
M->pps[i].pf, M->pps[i].nf, false);
ptr, M->pps[i].nf, true);

M->pps[i].pf = IntArray(M->pps[i].nf);
memcpy(M->pps[i].pf, ptr, M->pps[i].nf * sizeof(Int));

// TODO(Imad): error check
ptr = NULL;
K_NUMPY::getFromNumpyArray(PyList_GetItem(PATCH, 2),
M->pps[i].pn, M->pps[i].nf, false);
ptr, M->pps[i].nf, true);

M->pps[i].pn = IntArray(M->pps[i].nf);
memcpy(M->pps[i].pn, ptr, M->pps[i].nf * sizeof(Int));

// Zero-based
for (Int j = 0; j < M->pps[i].nf; j++) {
Expand Down
2 changes: 2 additions & 0 deletions Cassiopee/XCore/XCore/AdaptMesh/MeshComm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,8 @@ Int Mesh_redistribute(Mesh *M, Int *cmap)

assert(rpdist[M->npc] == np);

XFREE(rpoints);

// Send coordinates

if (M->pid == 0) puts(" Exchanging point coordinates...");
Expand Down
2 changes: 2 additions & 0 deletions Cassiopee/XCore/XCore/AdaptMesh/MeshIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,8 @@ PyObject *export_conformal_mesh(Mesh *M)
}
}

RELEASESHAREDU(karray, f, cn);

PyObject *out = PyList_New(0);

PyList_Append(out, karray);
Expand Down
14 changes: 7 additions & 7 deletions Cassiopee/XCore/XCore/AdaptMesh/MeshRefine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ void Mesh_get_ref_entities(Mesh *M, std::vector<Int> &ref_cells,
for (Int fid : ref_faces) {
Int *face = Mesh_get_face(M, fid);
Int *frange = Mesh_get_frange(M, fid);
Int size = 2 * M->fstride[fid];
assert(size == 8);

for (Int i = 0; i < M->fstride[fid]; i++) {
if (frange[i] == 2) continue;
for (Int i = 0; i < size; i += 2) {
if (frange[i/2] == 2) continue;

Int *pn = face + 2*i;

Int p = pn[0];
assert(pn[1] == -1);
Int q = pn[2];
Int p = face[i];
assert(face[i+1] == -1);
Int q = face[(i+2)%size];

UEdge E(p, q);
auto it = ref_edges.find(E);
Expand Down
10 changes: 8 additions & 2 deletions Cassiopee/XCore/XCore/PyTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,17 @@ def AdaptMesh_ExtractMesh(t, conformize=1):
def AdaptMesh_ExtractOwners(AM):
return xcore.AdaptMesh_ExtractOwners(AM)

def AdaptMesh_ExtractNeighbours(AM):
return xcore.AdaptMesh_ExtractNeighbours(AM)

def AdaptMesh_ExtractCellLevels(AM):
return xcore.AdaptMesh_ExtractCellLevels(AM)

def AdaptMesh_ExtractNeighbourCellLevels(AM):
return xcore.AdaptMesh_ExtractNeighbourCellLevels(AM)
def AdaptMesh_ExtractCellRanges(AM):
return xcore.AdaptMesh_ExtractCellRanges(AM)

def AdaptMesh_ExtractHaloCellLevels(AM):
return xcore.AdaptMesh_ExtractHaloCellLevels(AM)


################################################################################
Expand Down
21 changes: 20 additions & 1 deletion Cassiopee/XCore/XCore/chunk2partNGon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ PyObject* K_XCORE::chunk2partNGon(PyObject *self, PyObject *args)
}

std::vector<E_Int> part(ncells);
ret = SCOTCH_dgraphPart(&graph, nproc, &strat, &part[0]);
ret = SCOTCH_dgraphPart(&graph, nproc, &strat, &part[0]);

if (ret != 0) {
fprintf(stderr, "SCOTCH_dgraphPart(): Failed to map graph\n");
Expand All @@ -436,6 +436,9 @@ PyObject* K_XCORE::chunk2partNGon(PyObject *self, PyObject *args)
if (rank == 0)
printf("Graph map OK\n");

SCOTCH_dgraphExit(&graph);
SCOTCH_stratExit(&strat);

// Send cells to their target proc!
std::vector<int> c_scount(nproc, 0);
std::vector<int> c_rcount(nproc, 0);
Expand Down Expand Up @@ -790,6 +793,9 @@ PyObject* K_XCORE::chunk2partNGon(PyObject *self, PyObject *args)
&rdata[0], &rcount[0], &rdist[0], XMPI_INT,
MPI_COMM_WORLD);


XFREE(faces_dist);

std::vector<E_Int> pneis;

E_Int nif = 0;
Expand Down Expand Up @@ -1063,8 +1069,14 @@ PyObject* K_XCORE::chunk2partNGon(PyObject *self, PyObject *args)
Py_DECREF(f);
Py_DECREF(n);
PyList_Append(comm_data, arr);

delete ppatches[i];
}

delete [] ppatches;



PyList_Append(out, comm_data);
Py_DECREF(comm_data);

Expand Down Expand Up @@ -1118,6 +1130,8 @@ PyObject* K_XCORE::chunk2partNGon(PyObject *self, PyObject *args)
Py_DECREF(clist);
}

XFREE(cells_dist);

// 9 must be an array of FlowSolutions chunks
o = PyList_GetItem(l, 8);
E_Int psize = PyList_Size(o);
Expand Down Expand Up @@ -1166,6 +1180,8 @@ PyObject* K_XCORE::chunk2partNGon(PyObject *self, PyObject *args)
Py_DECREF(plist);
}

XFREE(points_dist);

// 10 must be an array of PointList chunks
o = PyList_GetItem(l, 9);
E_Int nbc = PyList_Size(o);
Expand All @@ -1191,6 +1207,9 @@ PyObject* K_XCORE::chunk2partNGon(PyObject *self, PyObject *args)
// Note(Imad): we could free up plists[i] and bcsize[i] here
}

XFREE(plists);
XFREE(bcsize);

// make local PE
std::unordered_map<E_Int, std::vector<E_Int>> lPE;
for (E_Int i = 0; i < nncells; i++) {
Expand Down
4 changes: 3 additions & 1 deletion Cassiopee/XCore/XCore/xcore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ static PyMethodDef Pyxcore [] =
{"AdaptMesh_ExtractMesh", K_XCORE::AdaptMesh_ExtractMesh, METH_VARARGS},

{"AdaptMesh_ExtractOwners", K_XCORE::AdaptMesh_ExtractOwners, METH_VARARGS},
{"AdaptMesh_ExtractNeighbours", K_XCORE::AdaptMesh_ExtractNeighbours, METH_VARARGS},
{"AdaptMesh_ExtractCellLevels", K_XCORE::AdaptMesh_ExtractCellLevels, METH_VARARGS},
{"AdaptMesh_ExtractNeighbourCellLevels", K_XCORE::AdaptMesh_ExtractNeighbourCellLevels, METH_VARARGS},
{"AdaptMesh_ExtractCellRanges", K_XCORE::AdaptMesh_ExtractCellRanges, METH_VARARGS},
{"AdaptMesh_ExtractHaloCellLevels", K_XCORE::AdaptMesh_ExtractHaloCellLevels, METH_VARARGS},

{"intersectSurf", K_XCORE::intersectSurf, METH_VARARGS},
{"removeIntersectingKPlanes", K_XCORE::removeIntersectingKPlanes, METH_VARARGS},
Expand Down
4 changes: 3 additions & 1 deletion Cassiopee/XCore/XCore/xcore.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ namespace K_XCORE
PyObject *AdaptMesh_ExtractMesh(PyObject *self, PyObject *args);

PyObject *AdaptMesh_ExtractOwners(PyObject *self, PyObject *args);
PyObject *AdaptMesh_ExtractNeighbours(PyObject *self, PyObject *args);
PyObject *AdaptMesh_ExtractCellLevels(PyObject *self, PyObject *args);
PyObject *AdaptMesh_ExtractNeighbourCellLevels(PyObject *self, PyObject *args);
PyObject *AdaptMesh_ExtractCellRanges(PyObject *self, PyObject *args);
PyObject *AdaptMesh_ExtractHaloCellLevels(PyObject *self, PyObject *args);

PyObject *intersectSurf(PyObject *self, PyObject *args);
PyObject *removeIntersectingKPlanes(PyObject *self, PyObject *args);
Expand Down
15 changes: 5 additions & 10 deletions Cassiopee/XCore/setup.scons
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,20 @@ if mpi: libraries += mpiLibs
libraryDirs += paths; libraries += libs

# Specific options for scotch
#opt1 =['-DCOMMON_FILE_COMPRESS_GZ','-DCOMMON_PTHREAD',
# '-DCOMMON_RANDOM_FIXED_SEED', '-DSCOTCH_DETERMINISTIC',
# '-DSCOTCH_RENAME','-DIDXSIZE64','-DSCOTCH_MPI_ASYNC_COLL',
# '-DSCOTCH_PTHREAD','-DSCOTCH_PTHREAD_MPI',
# '-DSCOTCH_VERSION_NUM=7','-DSCOTCH_RELEASE_NUM=0','-DSCOTCH_PATCHLEVEL_NUM=4',
# '-IXCore/scotch']

opt1 =['-DCOMMON_FILE_COMPRESS_GZ',
opt1 =['-DCOMMON_FILE_COMPRESS_GZ','-DCOMMON_PTHREAD',
'-DCOMMON_RANDOM_FIXED_SEED', '-DSCOTCH_DETERMINISTIC',
'-DSCOTCH_RENAME','-DIDXSIZE64','-DSCOTCH_MPI_ASYNC_COLL',
'-DSCOTCH_PTHREAD','-DSCOTCH_PTHREAD_MPI',
'-DSCOTCH_VERSION_NUM=7','-DSCOTCH_RELEASE_NUM=0','-DSCOTCH_PATCHLEVEL_NUM=4',
'-IXCore/scotch']

opt1_1 = ['-DSCOTCH_PTSCOTCH']
#opt1_1 = []

if Dist.DEBUG: opt1 += ['-DSCOTCH_DEBUG_FULL']

if Dist.GDOUBLEINT: opt1 += ['-DINTSIZE64']
else: opt1 += ['-DINTSIZE32']
if cc == 'gcc': opt1 += [] # ['-Wrestrict']
if cc == 'gcc': opt1 += ['-Drestrict=__restrict'] # ['-Wrestrict']
elif cc == 'pgcc': opt1 += []
elif cc == 'nvc': opt1 += []
elif cc == 'icx': opt1 += []
Expand Down

0 comments on commit 37696c3

Please sign in to comment.