diff --git a/Cassiopee/XCore/XCore/AdaptMesh/AdaptMesh_AssignRefData.cpp b/Cassiopee/XCore/XCore/AdaptMesh/AdaptMesh_AssignRefData.cpp index dda359181..ccba4d9ae 100644 --- a/Cassiopee/XCore/XCore/AdaptMesh/AdaptMesh_AssignRefData.cpp +++ b/Cassiopee/XCore/XCore/AdaptMesh/AdaptMesh_AssignRefData.cpp @@ -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++) { diff --git a/Cassiopee/XCore/XCore/AdaptMesh/AdaptMesh_Init.cpp b/Cassiopee/XCore/XCore/AdaptMesh/AdaptMesh_Init.cpp index b1ac4add1..dbe290198 100644 --- a/Cassiopee/XCore/XCore/AdaptMesh/AdaptMesh_Init.cpp +++ b/Cassiopee/XCore/XCore/AdaptMesh/AdaptMesh_Init.cpp @@ -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)); @@ -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++) { diff --git a/Cassiopee/XCore/XCore/AdaptMesh/MeshComm.cpp b/Cassiopee/XCore/XCore/AdaptMesh/MeshComm.cpp index ed08f370e..f2f5cfcc9 100644 --- a/Cassiopee/XCore/XCore/AdaptMesh/MeshComm.cpp +++ b/Cassiopee/XCore/XCore/AdaptMesh/MeshComm.cpp @@ -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..."); diff --git a/Cassiopee/XCore/XCore/AdaptMesh/MeshIO.cpp b/Cassiopee/XCore/XCore/AdaptMesh/MeshIO.cpp index b11595721..13f68d13b 100644 --- a/Cassiopee/XCore/XCore/AdaptMesh/MeshIO.cpp +++ b/Cassiopee/XCore/XCore/AdaptMesh/MeshIO.cpp @@ -610,6 +610,8 @@ PyObject *export_conformal_mesh(Mesh *M) } } + RELEASESHAREDU(karray, f, cn); + PyObject *out = PyList_New(0); PyList_Append(out, karray); diff --git a/Cassiopee/XCore/XCore/AdaptMesh/MeshRefine.cpp b/Cassiopee/XCore/XCore/AdaptMesh/MeshRefine.cpp index 59e714802..31998a8b4 100644 --- a/Cassiopee/XCore/XCore/AdaptMesh/MeshRefine.cpp +++ b/Cassiopee/XCore/XCore/AdaptMesh/MeshRefine.cpp @@ -47,15 +47,15 @@ void Mesh_get_ref_entities(Mesh *M, std::vector &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); diff --git a/Cassiopee/XCore/XCore/chunk2partNGon.cpp b/Cassiopee/XCore/XCore/chunk2partNGon.cpp index 3ac13d27d..a43674f47 100644 --- a/Cassiopee/XCore/XCore/chunk2partNGon.cpp +++ b/Cassiopee/XCore/XCore/chunk2partNGon.cpp @@ -427,7 +427,7 @@ PyObject* K_XCORE::chunk2partNGon(PyObject *self, PyObject *args) } std::vector 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"); @@ -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 c_scount(nproc, 0); std::vector c_rcount(nproc, 0); @@ -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 pneis; E_Int nif = 0; @@ -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); @@ -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); @@ -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); @@ -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> lPE; for (E_Int i = 0; i < nncells; i++) { diff --git a/Cassiopee/XCore/setup.scons b/Cassiopee/XCore/setup.scons index 9c0d2eee2..acf289327 100644 --- a/Cassiopee/XCore/setup.scons +++ b/Cassiopee/XCore/setup.scons @@ -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 += []