Code Monkey home page Code Monkey logo

Comments (6)

blink1073 avatar blink1073 commented on July 19, 2024

That is a good idea. I could use posix_ipc as an optional dependency. I'll try it out.

from oct2py.

blink1073 avatar blink1073 commented on July 19, 2024

Do you know of a way to open an mmap file in Octave?

from oct2py.

drhirsch avatar drhirsch commented on July 19, 2024

No, I found the 2012 message that you may have seen from Jordi saying that mmap was not in Octave yet as it is in Matlab.

I am not sure if mmap can help this situation:
I pass in a variable ~500MByte in size along with several smaller variables and parameters that are manipulated with an .m script. The computation takes about 100 milliseconds, but the /tmp file I/O takes far longer than that in the oct2py .mat file passing.

Following your very sensible recommendations in the documentation, I should modify my .m file to not mindlessly pass the 500MByte variable repeatedly, but the .m file is a decade-old well-respected package that for data fidelity reasons people wouldn't want to modify.

A trivial example of what causes the file I/O issue is:

import numpy as np
from oct2py import octave

A = np.ones((2000,20000),dtype=np.float64) #320Mbyte

for i in np.arange(10):
    y = octave.prod(A,i)

What I did to solve this was to port the actual function to Python. I have done this a few times already for various functions, I try them out on my data with oct2py, but due to file I/O hampering speed, I port interesting functions from Matlab to Python.

Implicit in this is that EVERY value of large matrix A is used every time, that's why I wasn't immediately sure mmap would help -- though you may be thinking of some novel trick that I haven't thought of.

from oct2py.

blink1073 avatar blink1073 commented on July 19, 2024

Okay, I added temp_dir as an optional argument to Oct2Py, which can be /run/shm if desired. That puts the burden on the user to set up the shared memory outside of oct2py. Sound good?

from oct2py.

drhirsch avatar drhirsch commented on July 19, 2024

Yes I noticed over 4 times speedup with the silly test code below. I should try it with the way I actually use the function, but 4 times speedup is pretty good (and I'm testing with an SSD, so HDD users should see substantially more improvement).

Now Windows users can use free RAM drive software while Mac/Linux can use built-in RAM drive.
Thank you so much! I should have made the pull request myself.

import numpy as np
import oct2py
from time import time

octmp = oct2py.Oct2Py()
ocram = oct2py.Oct2Py(temp_dir='/run/shm')

A = np.ones((2000,20000),dtype=np.float64) #320Mbyte

tic = time()
for i in np.arange(10):
    y = A*i
print(str(time()-tic) + ' seconds using Numpy')

tic = time()
for i in np.arange(10):
    y = octmp.prod(A,i)
print(str(time()-tic) + ' seconds using /tmp')

tic = time()
for i in np.arange(10):
    y = ocram.prod(A,i)
print(str(time()-tic) + ' seconds using /run/shm RAM')
0.702534914017 seconds using Numpy
62.1404719353 seconds using /tmp
14.0810651779 seconds using /run/shm RAM

from oct2py.

blink1073 avatar blink1073 commented on July 19, 2024

Excellent, thank you for the great suggestions.

from oct2py.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.