Re: failed to allocate memory for 'P'

From: Sander Valcke <Sander.Valcke_at_UGent.be>
Date: Fri, 29 Jan 2010 14:39:04 +0100

Hi Holly,

do you have 2 GB per node or per processor? If the latter I don't really
see the problem, you are allocating 920 MB for the P array, 100 MB for
the communication buffer.

A thourough way of knowing how much memory is being allocated is to
replace all malloc calls by e.g. my_malloc, with my_malloc something of
the form:

void*
my_malloc(int numBytes, int errorCode, char* description)
{
  void * ptr=0;
  if (! (ptr = malloc(numBytes))){
    printf("(%d) %s: Failed to allocate %d bytes. Total allocated so
far: %d MB\n", ThisTask, description, numBytes, totalBytes/1000/1000);
    endrun(errorCode);
  }
  totalBytes += numBytes;

#ifdef VERBOSE_MALLOC
  printf("(%d) %s: Allocated %d bytes. Total allocated: %d MB\n",
ThisTask, description, numBytes, totalBytes / 1000 / 1000);
#endif

  return ptr;
}

with totalBytes a new global variable. To be concise you would then also
have to declare a "my_free" function, which should subtract the number
of freed bytes from the total number of allocated bytes. Compiling the
code with VERBOSE_MALLOC will then show you exactly how much memory is
being allocated.

For instance the following:

if(!(P = malloc(bytes = All.MaxPart * sizeof(struct particle_data))))
  {
    printf("failed to allocate memory for `P' (%g MB).\n", bytes /
(1024.0 * 1024.0));
    endrun(1);
   }

would then become:

P = my_malloc(All.MaxPart * sizeof(struct particle_data), 1, "P array");

you would have to do this for every malloc call (which is a bit
repetitive as there are about 100 malloc calls, but it's worth it). The
short path would be to have my_malloc only take 1 argument: the number
of bytes. Then you can just simply replace all malloc calls with
my_malloc (e.g. using sed).

Hope this helps,

Sander


Holly Trowland wrote:
>
> Hello Gadgeters
>
> I am trying to make a DM only simulation with 512^3 particles in a
> 100Mpc box. I am running it with mpi over 8 nodes, 4 processors per
> node and the processors are 2GB.
> The parameters I have that are relevant to the memory usage are:
> PartAllocFactor 1.6
> TreeAllocFactor 0.8
> BufferSize 100
>
> But Gadget gives me the message,
>
> failed to allocate memory for `P' (921.6 MB).
> task 10: endrun called with an error level of 1
>
> I don't know why it can't allocate this memory or what it is spending
> all the memory on, how can I fix this problem?
>
> Thanks
> Holly
>
>

-- 
--------------------------------------------------
| Sander Valcke                                  |
| Sterrenkundig Observatorium, Universiteit Gent |
| Krijgslaan 281 S9, B-9000 Gent, Belgium        |
| phone +32-9-264-4796  |  fax +32-9-264-4989    |
| https://sourceforge.net/projects/hyplot/       |
--------------------------------------------------
For the first time we have a weapon that nobody has used for thirty years.
This gives me great hope for the human race.
		-- Harlan Ellison
--------------------------------------------------
Received on 2010-01-29 14:52:52

This archive was generated by hypermail 2.3.0 : 2023-01-10 10:01:31 CET