Skip to content

Commit

Permalink
XCore: bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
imadhammani committed Jul 29, 2024
1 parent a4b76ef commit 165de4e
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 27 deletions.
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
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
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
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 165de4e

Please sign in to comment.