MethodicalAcceleratorDesign / MAD-NG

MAD Next-Generation official repository
GNU General Public License v3.0
32 stars 11 forks source link

mad_mem realloc fails without assert triggering #409

Closed PierreSchnizer closed 1 year ago

PierreSchnizer commented 1 year ago

The "mad_desc" objects stores precomputed coefficients. Memory buffers are allocated as required. Allocation fails on my test machine for the program given below.

If an "optimised" build is made, the assert will not stop the program, but ensure does.

This issue can be reproduced by the test program below (please increase np if it works on your machine).

Test program

#include <mad_desc.h>
#include <assert.h>
#include <stdio.h>

int main(void)
{
    const int nv=6, np=144;
    const ord_t mo=7, po=2;

    const desc_t* d = mad_desc_newvp (nv, mo, np, po);
    assert(d);
    mad_desc_info(d, NULL);

}

The output given is then

error:  mad-ng/src/mad_mem.c:219: : reallocation of main base ptr failed
ldeniau commented 1 year ago

The problem was more complicated than just returning a null pointer, the size was so big that overflows occurred before the first checks. The next release will check more strictly previous steps and allocation checks have been improved, and the output will become:

% rlwrap ./mad
    ____  __   ______    ______     |   Methodical Accelerator Design
     /  \/  \   /  _  \   /  _  \   |   release: 0.9.7_P (OSX 64)
    /  __   /  /  /_/ /  /  /_/ /   |   support: http://cern.ch/mad
   /__/  /_/  /__/ /_/  /_____ /    |   licence: GPL3 (C) CERN 2016+
                                    |   started: 2023-10-06 18:52:33

> d = MAD.damap{nv=6, mo=7, np=144, po=2}
warning: mad_desc.c:188: : gtpsa are very large (4958052 monomials),
    building descriptor may take some time,
    consider that multiplication is quadratic in size.
error: mad_desc.c:561: : gtpsa are too large (4958052 monomials),
    indexing matrix #slots for orders 4 x 2 = 2575644750 > 2^31

stack traceback:
    [C]: in function 'mad_desc_newvp'
    ./madl_gtpsa.mad:148: in function 'gtpsad'
    ./madl_damap.mad:153: in function 'map_ctor'
    ./madl_damap.mad:189: in function 'damap'
    stdin:1: in main chunk
    [C]: at 0x0104c0fba0
PierreSchnizer commented 1 year ago

Dear Laurent,

thanks for the nice fast fix. Now I understand why I had some bit "inconsisten" behaviour when I tried to use these parameters.

It happened in the beginning and I thought I had messed up witht the proper order of newvp.

Thanks for cleaning it uo and all the best for optimising LHC lattice,

Sincerely yours

Piere

--------------------Ursprüngliche Nachricht--------------------
Von: Laurent Deniau ***@***.***>
Gesendet: Freitag 6. Oktober 2023 18:54
An: MethodicalAcceleratorDesign/MAD ***@***.***>
CC: Pierre Schnizer ***@***.***>; Author
***@***.***>
Betreff: Re: [MethodicalAcceleratorDesign/MAD] mad_mem realloc fails
without assert triggering (PR #409)

The problem was more complicated than just returning a null pointer, the
size was so big that overflows occurred before the first checks. The next
release will check more strictly previous steps and allocation checks have
been improved, and the output will become:

% rlwrap ./mad
    ____  __   ______    ______     |   Methodical Accelerator Design
     /  \/  \   /  _  \   /  _  \   |   release: 0.9.7_P (OSX 64)
    /  __   /  /  /_/ /  /  /_/ /   |   support: http://cern.ch/mad
   /__/  /_/  /__/ /_/  /_____ /    |   licence: GPL3 (C) CERN 2016+
                                    |   started: 2023-10-06 18:52:33

> d = MAD.damap{nv=6, mo=7, np=144, po=2}
warning: mad_desc.c:188: : gtpsa are very large (4958052 monomials),
        building descriptor may take some time,
        consider that multiplication is quadratic in size.
error: mad_desc.c:561: : gtpsa are too large (4958052 monomials),
        indexing matrix #slots for orders 4 x 2 = 2575644750 > 2^31

stack traceback:
        [C]: in function 'mad_desc_newvp'
        ./madl_gtpsa.mad:148: in function 'gtpsad'
        ./madl_damap.mad:153: in function 'map_ctor'
        ./madl_damap.mad:189: in function 'damap'
        stdin:1: in main chunk
        [C]: at 0x0104c0fba0

—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: 
***@***.***>