Skip to content

Commit

Permalink
Merge pull request #174 from imadhammani/main
Browse files Browse the repository at this point in the history
XCore AdaptMesh: mem update
  • Loading branch information
benoit128 authored Sep 10, 2024
2 parents fd5569f + 179fe19 commit a63387e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 38 deletions.
14 changes: 12 additions & 2 deletions Cassiopee/XCore/XCore/AdaptMesh/MeshComm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ E_Int *map_cell_graph(Mesh *M, E_Int *cwgts)

E_Int *cmap = IntArray(M->nc);

if (M->pid == 0) puts("Partitionning graph...");
if (M->pid == 0) puts("Partitioning graph...");

ret = SCOTCH_dgraphPart(&graph, M->npc, &strat, cmap);
if (ret != 0) {
Expand Down Expand Up @@ -191,6 +191,16 @@ struct xyz {
static
E_Int Mesh_redistribute(Mesh *M, E_Int *cmap)
{
if (M->pid == 0) puts("Verifying mesh integrity...");

Mesh_set_orientation(M);

if (M->pid == 0) {
puts("Mesh integrity OK");
fflush(stdout);
}


// Allocate contiguous count arrays

E_Int count_size = M->npc;
Expand Down Expand Up @@ -1507,4 +1517,4 @@ E_Int Mesh_load_balance(Mesh *M)
MPI_Allreduce(&M->nf, &gnf, 1, XMPI_INT, MPI_SUM, MPI_COMM_WORLD);

return gret;
}
}
73 changes: 41 additions & 32 deletions Cassiopee/XCore/XCore/common/mem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,36 @@
*/
#include "mem.h"

void *xmalloc(size_t nbytes, const char *file, E_Int line)
void *xmalloc(E_Int nbytes, const char *file, E_Int line)
{
assert(nbytes >= 0);
void *ptr = malloc(nbytes);
if (ptr == NULL && nbytes > 0) {
fprintf(stderr, "\n Failed to allocate %.2f MB in file %s, line " SF_D_ "\n\n",
nbytes/1000000., file, line);
assert(0);
//abort();
}
return ptr;
if (nbytes < 0) {
fprintf(stderr, "trying to allocate a negative amount (%.2f) of bytes in file %s:%d\n",
nbytes/1000000.f, file, line);
abort();
}
void *ptr = malloc(nbytes);
if (ptr == NULL && nbytes > 0) {
fprintf(stderr, "\n Failed to allocate %.2f MB in file %s, line " SF_D_ "\n\n",
nbytes/1000000., file, line);
abort();
}
return ptr;
}

void *xcalloc(size_t count, size_t size, const char *file, E_Int line)
void *xcalloc(E_Int count, E_Int size, const char *file, E_Int line)
{
assert(count >= 0);
assert(size >= 0);
void *ptr = calloc(count, size);
if (ptr == NULL && size > 0) {
fprintf(stderr, "\n Failed to allocate %.2f MB in file %s, line " SF_D_ "\n\n",
count*size/1000000., file, line);
assert(0);
//abort();
}
return ptr;
if (count < 0) {
fprintf(stderr, "xcalloc: count (%d) is negative in file %s:%d\n", count, file, line);
abort();
}

void *ptr = calloc(count, size);
if (ptr == NULL && size > 0) {
fprintf(stderr, "\n Failed to allocate %.2f MB in file %s, line " SF_D_ "\n\n",
count*size/1000000., file, line);
abort();
}
return ptr;
}

void xfree(void *ptr, const char *file, E_Int line)
Expand All @@ -53,16 +58,20 @@ void xfree(void *ptr, const char *file, E_Int line)
}
}

void *xresize(void *ptr, size_t nbytes, const char *file, E_Int line)
void *xresize(void *ptr, E_Int nbytes, const char *file, E_Int line)
{
//assert(ptr);
assert(nbytes >= 0);
ptr = realloc(ptr, nbytes);
if (ptr == NULL && nbytes > 0) {
fprintf(stderr, "\n Failed to allocate %.2f MB in file %s, line " SF_D_ "\n\n",
nbytes/1000000., file, line);
assert(0);
//abort();
}
return ptr;

if (nbytes < 0) {
fprintf(stderr, "trying to resize to a negative amount (%.2f) of bytes in file %s:%d\n",
nbytes/1000000.f, file, line);
abort();
}

ptr = realloc(ptr, nbytes);
if (ptr == NULL && nbytes > 0) {
fprintf(stderr, "\n Failed to allocate %.2f MB in file %s, line " SF_D_ "\n\n",
nbytes/1000000., file, line);
abort();
}
return ptr;
}
8 changes: 4 additions & 4 deletions Cassiopee/XCore/XCore/common/mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
#define XRESIZE(ptr, nbytes) \
xresize((ptr), (nbytes), __FILE__, __LINE__)

void *xmalloc(size_t , const char *, E_Int);
void *xcalloc(size_t, size_t, const char *, E_Int);
void *xmalloc(E_Int, const char *, E_Int);
void *xcalloc(E_Int, E_Int, const char *, E_Int);
void xfree(void *, const char *, E_Int);
void *xresize(void *, size_t, const char *, E_Int);
void *xresize(void *, E_Int, const char *, E_Int);

#endif
#endif

0 comments on commit a63387e

Please sign in to comment.