@Kunda1 : Sorry I am no Cpp dev. I use python. But when I have issues on speed I usually try numba jit nopython (@njit), it really allows to reduce process time and works quite well with numpy. So may be it could be possible to speed up the slow part of the workbench with numba ?
numba jit nopython (@njit) allows to reduce process time and works quite well with numpy.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
Be nice to others! Read the FreeCAD code of conduct!
numba jit nopython (@njit) allows to reduce process time and works quite well with numpy.
Last edited by Kunda1 on Tue Aug 10, 2021 12:42 pm, edited 1 time in total.
Reason: Split off from https://forum.freecadweb.org/viewtopic.php?f=8&t=58132
Reason: Split off from https://forum.freecadweb.org/viewtopic.php?f=8&t=58132
Re: [Request] A dedicated NURBS workbench
What's one more dependency to our ever-growing list?!?
But nevertheless, thanks for the heads up. It would be cool to see it in action as a PoC in FreeCAD
But nevertheless, thanks for the heads up. It would be cool to see it in action as a PoC in FreeCAD
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Re: [Request] A dedicated NURBS workbench
I agree ! Here is a little example of code that will help you to see how it works and what are the gains :
Code: Select all
from numba import njit, jit, vectorize,prange
import numpy as np
import time
A=np.ones((6000,7000))
B=A.copy()
C=B.copy()
@njit(parallel=True,fastmath=True)
def add_mat_njit(A,B):
return A+2.*B/A+6*A/B
@njit(parallel=True,fastmath=True)
def add_mat_loop_njit(A,B,C):
for i in prange(0,A.shape[0]):
for j in prange(0,A.shape[1]):
C[i,j]=A[i,j]+2.*B[i,j]/A[i,j]+6*A[i,j]/B[i,j]
return C
@vectorize
def add_mat_vec(A,B):
return A+2.*B/A+6*A/B
add_mat_vec(A,B)
add_mat_njit(A,B)
add_mat_loop_njit(A,B,C)
t0=time.time()
for i in range(0,10):
add_mat_njit(A,B)
print("time in ms for numba nopython parallel with numpy version: {}".format((time.time()-t0)*100))
t0=time.time()
for i in range(0,10):
add_mat_vec(A,B)
print("time in ms for numba vectorize version: {}".format((time.time()-t0)*100))
t0=time.time()
for i in range(0,10):
add_mat_loop_njit(A,B,C)
print("time in ms for numba nopython parallel with double loop over array version: {}".format((time.time()-t0)*100))
t0=time.time()
for i in range(0,10):
A+2.*B/A+6*A/B
print("time in ms for numpy version: {}".format((time.time()-t0)*100))
time in ms for numba nopython parallel with numpy version: 65.48645496368408
time in ms for numba vectorize version: 75.65851211547852
time in ms for numba nopython parallel with double loop over array version: 59.387898445129395
time in ms for numpy version: 291.48826599121094
Note that if you want to // the code with explicit loops, you have to use prange instead of range
You can see that it is easy to change, easy to test and that it is simple to change for loops that can help, because working with array in numpy can lead to poor readability of the code.
It is absolutely necessary to be able to use nopython in order to have an increase of performances, it means that it could be necessary to isolate some object or create one that allows nopython.