Comments (5)
With python gil's own limitations, I don't think it's necessary to call the same numpy object with multiple threads from outside.
https://wiki.python.org/moin/GlobalInterpreterLock
from numpy.net.
@pkingwsd: right now, the GIL locking has not been put inside of each call to np. As stated in the pythonnet documentation you should do all calls to Python inside of the lock like this:
using (Py.GIL())
{
np.matmul(a, b);
}
Do you think it would be better to have this locking automatically in every API call or should the user put all his processing inside of a lock? I am undecided.
from numpy.net.
@henon : pls try it.np.matmul(a, b);// no response.
var a = np.arange(1000);
var b = np.arange(1000);
Task.Run(() => {
using (Py.GIL())
{
np.matmul(a, b);// no response
Console.WriteLine("work");
}
});
Console.ReadLine();
from numpy.net.
Before using background threads you need to call PythonEngine.BeginAllowThreads();
Check out this issue on pythonnet that explains it: pythonnet/pythonnet#109
Console.WriteLine("Efficient matrix multiplication with NumPy:");
// before starting the measurement, let us call numpy once to get the setup checks done.
var stopwatch = Stopwatch.StartNew();
np.arange(1);
var a1 = np.arange(60000).reshape(300, 200);
var a2 = np.arange(80000).reshape(200, 400);
var result = np.matmul(a1, a2);
stopwatch.Stop();
Console.WriteLine($"execution time with NumPy: {stopwatch.Elapsed.TotalMilliseconds}ms\n");
Console.WriteLine("Result:\n" + result.repr);
Console.WriteLine("executing on bg thread");
var a = np.arange(1000);
var b = np.arange(1000);
// https://github.com/pythonnet/pythonnet/issues/109
PythonEngine.BeginAllowThreads();
Task.Run(() =>
{
using (Py.GIL())
{
np.matmul(a, b);
Console.WriteLine("matmul on bg thread is done");
}
}).Wait();
Console.WriteLine("Press key");
Console.ReadKey();
from numpy.net.
awesome.
from numpy.net.
Related Issues (20)
- np.load of np.savez impossible to get values back out? HOT 3
- np.array leaks memory HOT 12
- Numpy hangs on exit since version 3.10.1.29 (last stable 3.7.1.28) HOT 7
- Support for CuPy HOT 1
- Please Sign and assign StrongName for Numpy Nuget package
- np.split HOT 12
- `Half` type arrays HOT 7
- Set conditions as NDArray Type HOT 3
- fft() failed: βindex -2 is out of bounds for axis 0 with size 1β HOT 9
- Problem with passing imaginery numbers HOT 3
- NDarray of DateTime HOT 3
- Azure AppService and System.DllNotFoundException: Could not load python311.dll with flags RTLD_NOW | RTLD_GLOBAL: python311.dll: cannot open shared object file: No such file or directory HOT 5
- Could not find platform dependent libraries <exec_prefix> HOT 6
- System.TypeLoadException: Could not load type 'Python.Runtime.PyLong' from assembly 'Python.Runtime, Version=3.0.1.0, Culture=neutral, PublicKeyToken=5000fea6cba702dd'. HOT 5
- Numpy.Bare build for Python 3.11 HOT 3
- np.sum(NDArray, axis:1) not supported? HOT 5
- Unable to use Numpy.NET from linux environment HOT 1
- Hello, has SciSharp/NumSharp stopped development and maintenance? HOT 1
- Unable to cast System.Double[][] to NDarray HOT 2
- failed to use "where" in Numpy.NET HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from numpy.net.