mpmath MemoryError on Windows port

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
ProudPagan
Posts: 35
Joined: Fri Apr 12, 2019 8:55 am

mpmath MemoryError on Windows port

Post by ProudPagan » Fri May 03, 2019 1:52 pm

Hi,

I am trying to port the mpmath package to MicroPython; the target will be Rasp-Pi-2, but I am
now developing on using the Windows port.

I got a little further than the OP in this post: viewtopic.php?t=3621 but have now hit a roadblock with this error:

Code: Select all

D:/RPi/python> micropython test.py
Traceback (most recent call last):
  File "test.py", line 1, in <module>
  File "D:/RPi/python/mpmath/__init__.py", line 5, in <module>
  File "D:/RPi/python/mpmath/ctx_fp.py", line 1, in <module>
  File "D:/RPi/python/mpmath/ctx_base.py", line 5, in <module>
  File "D:/RPi/python/mpmath/calculus/__init__.py", line 3, in <module>
MemoryError: memory allocation failed, allocating 10736 bytes
This is on a Windows machine with 8GB of RAM and I see 2.7GB still available!

I compiled the MicroPython binary from the top of Github sources compiled for Windows 10
(but I get he same error with Robert-HH's binary downloaded from here: https://github.com/robert-hh/Shared-Stuff)

Thanks!

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: mpmath MemoryError on Windows port

Post by jimmo » Fri May 03, 2019 2:12 pm

On the Windows (and Unix) builds, they still use the MicroPython heap (i.e. not system malloc), which is 1MiB by default (2MiB on 64-bit builds).

Can you try using the -heapsize argument and see if that helps?
Last edited by jimmo on Fri May 03, 2019 2:14 pm, edited 1 time in total.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: mpmath MemoryError on Windows port

Post by dhylands » Fri May 03, 2019 2:13 pm

The heap size for the unix port defaults to being 1 Mb (2Mb on a 64-bit machine).
https://github.com/micropython/micropyt ... main.c#L61

You can use the -X heapsize=number to adjust the heapsize when you start micropython. For example:

Code: Select all

1950 >./micropython -X heapsize=1M
MicroPython v1.9.4-782-geb446ec on 2019-02-24; linux version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> import gc
>>> gc.mem_free()
1034208
>>>

Code: Select all

1951 >./micropython -X heapsize=4M
MicroPython v1.9.4-782-geb446ec on 2019-02-24; linux version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> import gc
>>> gc.mem_free()
4143520
>>>

ProudPagan
Posts: 35
Joined: Fri Apr 12, 2019 8:55 am

Re: mpmath MemoryError on Windows port

Post by ProudPagan » Fri May 03, 2019 3:38 pm

Worked. Thanks so much!

Post Reply