[julia-users] Re: Spped, assigning arrays
Interesting. I'll be sure to have a look at JuliaFEM. On Monday, August 24, 2015 at 10:00:22 PM UTC+2, Jukka Aho wrote: > > How about saving integration points to custom type? > > type MyElement > gauss_points :: Matrix > end > > function MyElement() > gauss_points = [-1/sqrt(3) 1/sqrt(3) 1/sqrt(3) -1/sqrt(3); > -1/sqrt(3) -1/sqrt(3) 1/sqrt(3) 1/sqrt(3)] > MyElement(gauss_points) > end > > function get_gauss_points(el::MyElement) > el.gauss_points > end > > function get_gauss_points!(gp_xi::Matrix) > gp_xi[:] = [-1/sqrt(3) 1/sqrt(3) 1/sqrt(3) -1/sqrt(3); > -1/sqrt(3) -1/sqrt(3) 1/sqrt(3) 1/sqrt(3)] > end > > function get_gauss_points2!(gp_xi::Matrix) > gp_xi[1,1] = -1/sqrt(3) > gp_xi[2,1] = -1/sqrt(3) > gp_xi[1,2] = 1/sqrt(3) > gp_xi[2,2] = -1/sqrt(3) > gp_xi[1,3] = 1/sqrt(3) > gp_xi[2,3] = 1/sqrt(3) > gp_xi[1,4] = -1/sqrt(3) > gp_xi[2,4] = 1/sqrt(3) > end > > function test() > gp_xi = zeros(2,4) > get_gauss_points!(gp_xi) > get_gauss_points2!(gp_xi) > el = MyElement() > get_gauss_points(el) > > println("get_gauss_points!:") > @time for i=1:1e7 get_gauss_points!(gp_xi) end > > println("\nget_gauss_points2!") > @time for i=1:1e7 get_gauss_points2!(gp_xi) end > > println("get_gauss_points(el):") > @time for i=1:1e7 get_gauss_points(el) end > end > > test() > > Output: > > get_gauss_points!: >2.743 seconds (10 k allocations: 2747 MB, 16.94% gc time) > get_gauss_points2! > 145.800 milliseconds > get_gauss_points(el): >3.974 milliseconds > > > This is basically how we are doing it in JuliaFEM. This requires of course > some extra memory but you probably want/need to save some data to > integration points anyway if you develop incremental material models... > > Jukka > > maanantai 24. elokuuta 2015 20.31.56 UTC+3 Mohamed Moussa kirjoitti: >> >> Hey. I'm new to Julia. I'm playing around with 0.4 on Windows. I'm >> interested in writing finite element code for research purposes. >> >> Consider the following code >> >> function get_gauss_points!(gp_xi::Matrix) >> gp_xi = [-1/sqrt(3) 1/sqrt(3) 1/sqrt(3) -1/sqrt(3); >> -1/sqrt(3) -1/sqrt(3) 1/sqrt(3) 1/sqrt(3)] >> end >> >> function get_gauss_points2!(gp_xi::Matrix) >> gp_xi[1,1] = -1/sqrt(3) >> gp_xi[2,1] = -1/sqrt(3) >> gp_xi[1,2] = 1/sqrt(3) >> gp_xi[2,2] = -1/sqrt(3) >> gp_xi[1,3] = 1/sqrt(3) >> gp_xi[2,3] = 1/sqrt(3) >> gp_xi[1,4] = -1/sqrt(3) >> gp_xi[2,4] = 1/sqrt(3) >> end >> >> function test() >> gp_xi = zeros(2,4) >> get_gauss_points!(gp_xi) >> get_gauss_points2!(gp_xi) >> >> println("get_gauss_points!:") >> @time for i=1:1e7 get_gauss_points!(gp_xi) end >> >> println("\nget_gauss_points2!") >> @time for i=1:1e7 get_gauss_points2!(gp_xi) end >> end >> >> test() >> >> The output is >> get_gauss_points!: >> 1.129231 seconds (100.00 M allocations: 2.682 GB, 14.56% gc time) >> >> get_gauss_points2! >> 0.067619 seconds >> >> Using @profile shows that get_gauss_points! spends a lot of time in >> abstractarray. Is it possible to make get_gauss_points run as fast as >> get_gauss_points2 ? >> >> Cheers. >> >
[julia-users] Re: Spped, assigning arrays
Are you running the function once to let Julia compile it before doing the timing? Looking at code_lowered() for each shows the assignment happens via one larger or eight smaller GenSym temporaries. I see the slower of the two running ~1.5x not 50x the faster. On Monday, August 24, 2015 at 3:39:01 PM UTC-4, Mohamed Moussa wrote: > > That works for me, but it still seems to be creating the temporary array. > I suppose thats just what Julia does. > > On Monday, August 24, 2015 at 9:23:34 PM UTC+2, Mauricio Esteban Cuak > wrote: >> >> I thought this would work to assign in-place (but it does not) >> >> function get_gauss_points3!(gp_xi::Matrix) >> gp_xi[:] = [-1/sqrt(3) 1/sqrt(3) 1/sqrt(3) -1/sqrt(3); >> -1/sqrt(3) -1/sqrt(3) 1/sqrt(3) 1/sqrt(3)] >> end >> >> Is there any reason why this syntax shouldn't assign in-place? >> >> El lunes, 24 de agosto de 2015, 12:31:56 (UTC-5), Mohamed Moussa escribió: >>> >>> Hey. I'm new to Julia. I'm playing around with 0.4 on Windows. I'm >>> interested in writing finite element code for research purposes. >>> >>> Consider the following code >>> >>> function get_gauss_points!(gp_xi::Matrix) >>> gp_xi = [-1/sqrt(3) 1/sqrt(3) 1/sqrt(3) -1/sqrt(3); >>> -1/sqrt(3) -1/sqrt(3) 1/sqrt(3) 1/sqrt(3)] >>> end >>> >>> function get_gauss_points2!(gp_xi::Matrix) >>> gp_xi[1,1] = -1/sqrt(3) >>> gp_xi[2,1] = -1/sqrt(3) >>> gp_xi[1,2] = 1/sqrt(3) >>> gp_xi[2,2] = -1/sqrt(3) >>> gp_xi[1,3] = 1/sqrt(3) >>> gp_xi[2,3] = 1/sqrt(3) >>> gp_xi[1,4] = -1/sqrt(3) >>> gp_xi[2,4] = 1/sqrt(3) >>> end >>> >>> function test() >>> gp_xi = zeros(2,4) >>> get_gauss_points!(gp_xi) >>> get_gauss_points2!(gp_xi) >>> >>> println("get_gauss_points!:") >>> @time for i=1:1e7 get_gauss_points!(gp_xi) end >>> >>> println("\nget_gauss_points2!") >>> @time for i=1:1e7 get_gauss_points2!(gp_xi) end >>> end >>> >>> test() >>> >>> The output is >>> get_gauss_points!: >>> 1.129231 seconds (100.00 M allocations: 2.682 GB, 14.56% gc time) >>> >>> get_gauss_points2! >>> 0.067619 seconds >>> >>> Using @profile shows that get_gauss_points! spends a lot of time in >>> abstractarray. Is it possible to make get_gauss_points run as fast as >>> get_gauss_points2 ? >>> >>> Cheers. >>> >>
[julia-users] Re: Spped, assigning arrays
How about saving integration points to custom type? type MyElement gauss_points :: Matrix end function MyElement() gauss_points = [-1/sqrt(3) 1/sqrt(3) 1/sqrt(3) -1/sqrt(3); -1/sqrt(3) -1/sqrt(3) 1/sqrt(3) 1/sqrt(3)] MyElement(gauss_points) end function get_gauss_points(el::MyElement) el.gauss_points end function get_gauss_points!(gp_xi::Matrix) gp_xi[:] = [-1/sqrt(3) 1/sqrt(3) 1/sqrt(3) -1/sqrt(3); -1/sqrt(3) -1/sqrt(3) 1/sqrt(3) 1/sqrt(3)] end function get_gauss_points2!(gp_xi::Matrix) gp_xi[1,1] = -1/sqrt(3) gp_xi[2,1] = -1/sqrt(3) gp_xi[1,2] = 1/sqrt(3) gp_xi[2,2] = -1/sqrt(3) gp_xi[1,3] = 1/sqrt(3) gp_xi[2,3] = 1/sqrt(3) gp_xi[1,4] = -1/sqrt(3) gp_xi[2,4] = 1/sqrt(3) end function test() gp_xi = zeros(2,4) get_gauss_points!(gp_xi) get_gauss_points2!(gp_xi) el = MyElement() get_gauss_points(el) println("get_gauss_points!:") @time for i=1:1e7 get_gauss_points!(gp_xi) end println("\nget_gauss_points2!") @time for i=1:1e7 get_gauss_points2!(gp_xi) end println("get_gauss_points(el):") @time for i=1:1e7 get_gauss_points(el) end end test() Output: get_gauss_points!: 2.743 seconds (10 k allocations: 2747 MB, 16.94% gc time) get_gauss_points2! 145.800 milliseconds get_gauss_points(el): 3.974 milliseconds This is basically how we are doing it in JuliaFEM. This requires of course some extra memory but you probably want/need to save some data to integration points anyway if you develop incremental material models... Jukka maanantai 24. elokuuta 2015 20.31.56 UTC+3 Mohamed Moussa kirjoitti: > > Hey. I'm new to Julia. I'm playing around with 0.4 on Windows. I'm > interested in writing finite element code for research purposes. > > Consider the following code > > function get_gauss_points!(gp_xi::Matrix) > gp_xi = [-1/sqrt(3) 1/sqrt(3) 1/sqrt(3) -1/sqrt(3); > -1/sqrt(3) -1/sqrt(3) 1/sqrt(3) 1/sqrt(3)] > end > > function get_gauss_points2!(gp_xi::Matrix) > gp_xi[1,1] = -1/sqrt(3) > gp_xi[2,1] = -1/sqrt(3) > gp_xi[1,2] = 1/sqrt(3) > gp_xi[2,2] = -1/sqrt(3) > gp_xi[1,3] = 1/sqrt(3) > gp_xi[2,3] = 1/sqrt(3) > gp_xi[1,4] = -1/sqrt(3) > gp_xi[2,4] = 1/sqrt(3) > end > > function test() > gp_xi = zeros(2,4) > get_gauss_points!(gp_xi) > get_gauss_points2!(gp_xi) > > println("get_gauss_points!:") > @time for i=1:1e7 get_gauss_points!(gp_xi) end > > println("\nget_gauss_points2!") > @time for i=1:1e7 get_gauss_points2!(gp_xi) end > end > > test() > > The output is > get_gauss_points!: > 1.129231 seconds (100.00 M allocations: 2.682 GB, 14.56% gc time) > > get_gauss_points2! > 0.067619 seconds > > Using @profile shows that get_gauss_points! spends a lot of time in > abstractarray. Is it possible to make get_gauss_points run as fast as > get_gauss_points2 ? > > Cheers. >
Re: [julia-users] Re: Spped, assigning arrays
That is what Julia does. It's also what most other systems do unless they have some very clever optimizations. On Mon, Aug 24, 2015 at 3:39 PM, Mohamed Moussa wrote: > That works for me, but it still seems to be creating the temporary array. > I suppose thats just what Julia does. > > On Monday, August 24, 2015 at 9:23:34 PM UTC+2, Mauricio Esteban Cuak > wrote: >> >> I thought this would work to assign in-place (but it does not) >> >> function get_gauss_points3!(gp_xi::Matrix) >> gp_xi[:] = [-1/sqrt(3) 1/sqrt(3) 1/sqrt(3) -1/sqrt(3); >> -1/sqrt(3) -1/sqrt(3) 1/sqrt(3) 1/sqrt(3)] >> end >> >> Is there any reason why this syntax shouldn't assign in-place? >> >> El lunes, 24 de agosto de 2015, 12:31:56 (UTC-5), Mohamed Moussa escribió: >>> >>> Hey. I'm new to Julia. I'm playing around with 0.4 on Windows. I'm >>> interested in writing finite element code for research purposes. >>> >>> Consider the following code >>> >>> function get_gauss_points!(gp_xi::Matrix) >>> gp_xi = [-1/sqrt(3) 1/sqrt(3) 1/sqrt(3) -1/sqrt(3); >>> -1/sqrt(3) -1/sqrt(3) 1/sqrt(3) 1/sqrt(3)] >>> end >>> >>> function get_gauss_points2!(gp_xi::Matrix) >>> gp_xi[1,1] = -1/sqrt(3) >>> gp_xi[2,1] = -1/sqrt(3) >>> gp_xi[1,2] = 1/sqrt(3) >>> gp_xi[2,2] = -1/sqrt(3) >>> gp_xi[1,3] = 1/sqrt(3) >>> gp_xi[2,3] = 1/sqrt(3) >>> gp_xi[1,4] = -1/sqrt(3) >>> gp_xi[2,4] = 1/sqrt(3) >>> end >>> >>> function test() >>> gp_xi = zeros(2,4) >>> get_gauss_points!(gp_xi) >>> get_gauss_points2!(gp_xi) >>> >>> println("get_gauss_points!:") >>> @time for i=1:1e7 get_gauss_points!(gp_xi) end >>> >>> println("\nget_gauss_points2!") >>> @time for i=1:1e7 get_gauss_points2!(gp_xi) end >>> end >>> >>> test() >>> >>> The output is >>> get_gauss_points!: >>> 1.129231 seconds (100.00 M allocations: 2.682 GB, 14.56% gc time) >>> >>> get_gauss_points2! >>> 0.067619 seconds >>> >>> Using @profile shows that get_gauss_points! spends a lot of time in >>> abstractarray. Is it possible to make get_gauss_points run as fast as >>> get_gauss_points2 ? >>> >>> Cheers. >>> >>
[julia-users] Re: Spped, assigning arrays
That works for me, but it still seems to be creating the temporary array. I suppose thats just what Julia does. On Monday, August 24, 2015 at 9:23:34 PM UTC+2, Mauricio Esteban Cuak wrote: > > I thought this would work to assign in-place (but it does not) > > function get_gauss_points3!(gp_xi::Matrix) > gp_xi[:] = [-1/sqrt(3) 1/sqrt(3) 1/sqrt(3) -1/sqrt(3); > -1/sqrt(3) -1/sqrt(3) 1/sqrt(3) 1/sqrt(3)] > end > > Is there any reason why this syntax shouldn't assign in-place? > > El lunes, 24 de agosto de 2015, 12:31:56 (UTC-5), Mohamed Moussa escribió: >> >> Hey. I'm new to Julia. I'm playing around with 0.4 on Windows. I'm >> interested in writing finite element code for research purposes. >> >> Consider the following code >> >> function get_gauss_points!(gp_xi::Matrix) >> gp_xi = [-1/sqrt(3) 1/sqrt(3) 1/sqrt(3) -1/sqrt(3); >> -1/sqrt(3) -1/sqrt(3) 1/sqrt(3) 1/sqrt(3)] >> end >> >> function get_gauss_points2!(gp_xi::Matrix) >> gp_xi[1,1] = -1/sqrt(3) >> gp_xi[2,1] = -1/sqrt(3) >> gp_xi[1,2] = 1/sqrt(3) >> gp_xi[2,2] = -1/sqrt(3) >> gp_xi[1,3] = 1/sqrt(3) >> gp_xi[2,3] = 1/sqrt(3) >> gp_xi[1,4] = -1/sqrt(3) >> gp_xi[2,4] = 1/sqrt(3) >> end >> >> function test() >> gp_xi = zeros(2,4) >> get_gauss_points!(gp_xi) >> get_gauss_points2!(gp_xi) >> >> println("get_gauss_points!:") >> @time for i=1:1e7 get_gauss_points!(gp_xi) end >> >> println("\nget_gauss_points2!") >> @time for i=1:1e7 get_gauss_points2!(gp_xi) end >> end >> >> test() >> >> The output is >> get_gauss_points!: >> 1.129231 seconds (100.00 M allocations: 2.682 GB, 14.56% gc time) >> >> get_gauss_points2! >> 0.067619 seconds >> >> Using @profile shows that get_gauss_points! spends a lot of time in >> abstractarray. Is it possible to make get_gauss_points run as fast as >> get_gauss_points2 ? >> >> Cheers. >> >
[julia-users] Re: Spped, assigning arrays
Correction (and sorry for the noise), function get_gauss_points3! function get_gauss_points3!(gp_xi::Matrix) gp_xi[:] = [-1/sqrt(3) 1/sqrt(3) 1/sqrt(3) -1/sqrt(3); -1/sqrt(3) -1/sqrt(3) 1/sqrt(3) 1/sqrt(3)] end DOES assign in-place. However, it's 50 times slower that assigning element by element (which I find surprising for a 2 by 4 matrix). get_gauss_points!: elapsed time: 3.176810571 seconds (272096 bytes allocated, 43.29% gc time) get_gauss_points2! elapsed time: 0.062963865 seconds (96 bytes allocated) get_gauss_points3! elapsed time: 3.449866225 seconds (272096 bytes allocated, 40.87% gc time) I'm using 0.3.11 El lunes, 24 de agosto de 2015, 14:26:42 (UTC-5), Mohamed Moussa escribió: > > Err, oops. Good point. > > On Monday, August 24, 2015 at 7:47:35 PM UTC+2, Scott Jones wrote: >> >> Have you checked the results from `get_gauss_points!` ? I'm not even >> sure that is doing what you think. >> Instead of setting the values in the mutable array, it is setting the >> local variable (and creating a new matrix) every time. >> >> >> On Monday, August 24, 2015 at 7:31:56 PM UTC+2, Mohamed Moussa wrote: >>> >>> Hey. I'm new to Julia. I'm playing around with 0.4 on Windows. I'm >>> interested in writing finite element code for research purposes. >>> >>> Consider the following code >>> >>> function get_gauss_points!(gp_xi::Matrix) >>> gp_xi = [-1/sqrt(3) 1/sqrt(3) 1/sqrt(3) -1/sqrt(3); >>> -1/sqrt(3) -1/sqrt(3) 1/sqrt(3) 1/sqrt(3)] >>> end >>> >>> function get_gauss_points2!(gp_xi::Matrix) >>> gp_xi[1,1] = -1/sqrt(3) >>> gp_xi[2,1] = -1/sqrt(3) >>> gp_xi[1,2] = 1/sqrt(3) >>> gp_xi[2,2] = -1/sqrt(3) >>> gp_xi[1,3] = 1/sqrt(3) >>> gp_xi[2,3] = 1/sqrt(3) >>> gp_xi[1,4] = -1/sqrt(3) >>> gp_xi[2,4] = 1/sqrt(3) >>> end >>> >>> function test() >>> gp_xi = zeros(2,4) >>> get_gauss_points!(gp_xi) >>> get_gauss_points2!(gp_xi) >>> >>> println("get_gauss_points!:") >>> @time for i=1:1e7 get_gauss_points!(gp_xi) end >>> >>> println("\nget_gauss_points2!") >>> @time for i=1:1e7 get_gauss_points2!(gp_xi) end >>> end >>> >>> test() >>> >>> The output is >>> get_gauss_points!: >>> 1.129231 seconds (100.00 M allocations: 2.682 GB, 14.56% gc time) >>> >>> get_gauss_points2! >>> 0.067619 seconds >>> >>> Using @profile shows that get_gauss_points! spends a lot of time in >>> abstractarray. Is it possible to make get_gauss_points run as fast as >>> get_gauss_points2 ? >>> >>> Cheers. >>> >>
[julia-users] Re: Spped, assigning arrays
Err, oops. Good point. On Monday, August 24, 2015 at 7:47:35 PM UTC+2, Scott Jones wrote: > > Have you checked the results from `get_gauss_points!` ? I'm not even sure > that is doing what you think. > Instead of setting the values in the mutable array, it is setting the > local variable (and creating a new matrix) every time. > > > On Monday, August 24, 2015 at 7:31:56 PM UTC+2, Mohamed Moussa wrote: >> >> Hey. I'm new to Julia. I'm playing around with 0.4 on Windows. I'm >> interested in writing finite element code for research purposes. >> >> Consider the following code >> >> function get_gauss_points!(gp_xi::Matrix) >> gp_xi = [-1/sqrt(3) 1/sqrt(3) 1/sqrt(3) -1/sqrt(3); >> -1/sqrt(3) -1/sqrt(3) 1/sqrt(3) 1/sqrt(3)] >> end >> >> function get_gauss_points2!(gp_xi::Matrix) >> gp_xi[1,1] = -1/sqrt(3) >> gp_xi[2,1] = -1/sqrt(3) >> gp_xi[1,2] = 1/sqrt(3) >> gp_xi[2,2] = -1/sqrt(3) >> gp_xi[1,3] = 1/sqrt(3) >> gp_xi[2,3] = 1/sqrt(3) >> gp_xi[1,4] = -1/sqrt(3) >> gp_xi[2,4] = 1/sqrt(3) >> end >> >> function test() >> gp_xi = zeros(2,4) >> get_gauss_points!(gp_xi) >> get_gauss_points2!(gp_xi) >> >> println("get_gauss_points!:") >> @time for i=1:1e7 get_gauss_points!(gp_xi) end >> >> println("\nget_gauss_points2!") >> @time for i=1:1e7 get_gauss_points2!(gp_xi) end >> end >> >> test() >> >> The output is >> get_gauss_points!: >> 1.129231 seconds (100.00 M allocations: 2.682 GB, 14.56% gc time) >> >> get_gauss_points2! >> 0.067619 seconds >> >> Using @profile shows that get_gauss_points! spends a lot of time in >> abstractarray. Is it possible to make get_gauss_points run as fast as >> get_gauss_points2 ? >> >> Cheers. >> >
[julia-users] Re: Spped, assigning arrays
I thought this would work to assign in-place (but it does not) function get_gauss_points3!(gp_xi::Matrix) gp_xi[:] = [-1/sqrt(3) 1/sqrt(3) 1/sqrt(3) -1/sqrt(3); -1/sqrt(3) -1/sqrt(3) 1/sqrt(3) 1/sqrt(3)] end Is there any reason why this syntax shouldn't assign in-place? El lunes, 24 de agosto de 2015, 12:31:56 (UTC-5), Mohamed Moussa escribió: > > Hey. I'm new to Julia. I'm playing around with 0.4 on Windows. I'm > interested in writing finite element code for research purposes. > > Consider the following code > > function get_gauss_points!(gp_xi::Matrix) > gp_xi = [-1/sqrt(3) 1/sqrt(3) 1/sqrt(3) -1/sqrt(3); > -1/sqrt(3) -1/sqrt(3) 1/sqrt(3) 1/sqrt(3)] > end > > function get_gauss_points2!(gp_xi::Matrix) > gp_xi[1,1] = -1/sqrt(3) > gp_xi[2,1] = -1/sqrt(3) > gp_xi[1,2] = 1/sqrt(3) > gp_xi[2,2] = -1/sqrt(3) > gp_xi[1,3] = 1/sqrt(3) > gp_xi[2,3] = 1/sqrt(3) > gp_xi[1,4] = -1/sqrt(3) > gp_xi[2,4] = 1/sqrt(3) > end > > function test() > gp_xi = zeros(2,4) > get_gauss_points!(gp_xi) > get_gauss_points2!(gp_xi) > > println("get_gauss_points!:") > @time for i=1:1e7 get_gauss_points!(gp_xi) end > > println("\nget_gauss_points2!") > @time for i=1:1e7 get_gauss_points2!(gp_xi) end > end > > test() > > The output is > get_gauss_points!: > 1.129231 seconds (100.00 M allocations: 2.682 GB, 14.56% gc time) > > get_gauss_points2! > 0.067619 seconds > > Using @profile shows that get_gauss_points! spends a lot of time in > abstractarray. Is it possible to make get_gauss_points run as fast as > get_gauss_points2 ? > > Cheers. >
[julia-users] Re: Spped, assigning arrays
You may want to modify your first function as something like `gp_xi = get_gauss_points!()`, so that you will at least get the correct result. Since it will only take 1.129231/1e7 seconds, It won't be the bottleneck of your program. On Monday, August 24, 2015 at 7:31:56 PM UTC+2, Mohamed Moussa wrote: > > Hey. I'm new to Julia. I'm playing around with 0.4 on Windows. I'm > interested in writing finite element code for research purposes. > > Consider the following code > > function get_gauss_points!(gp_xi::Matrix) > gp_xi = [-1/sqrt(3) 1/sqrt(3) 1/sqrt(3) -1/sqrt(3); > -1/sqrt(3) -1/sqrt(3) 1/sqrt(3) 1/sqrt(3)] > end > > function get_gauss_points2!(gp_xi::Matrix) > gp_xi[1,1] = -1/sqrt(3) > gp_xi[2,1] = -1/sqrt(3) > gp_xi[1,2] = 1/sqrt(3) > gp_xi[2,2] = -1/sqrt(3) > gp_xi[1,3] = 1/sqrt(3) > gp_xi[2,3] = 1/sqrt(3) > gp_xi[1,4] = -1/sqrt(3) > gp_xi[2,4] = 1/sqrt(3) > end > > function test() > gp_xi = zeros(2,4) > get_gauss_points!(gp_xi) > get_gauss_points2!(gp_xi) > > println("get_gauss_points!:") > @time for i=1:1e7 get_gauss_points!(gp_xi) end > > println("\nget_gauss_points2!") > @time for i=1:1e7 get_gauss_points2!(gp_xi) end > end > > test() > > The output is > get_gauss_points!: > 1.129231 seconds (100.00 M allocations: 2.682 GB, 14.56% gc time) > > get_gauss_points2! > 0.067619 seconds > > Using @profile shows that get_gauss_points! spends a lot of time in > abstractarray. Is it possible to make get_gauss_points run as fast as > get_gauss_points2 ? > > Cheers. >
[julia-users] Re: Spped, assigning arrays
Have you checked the results from `get_gauss_points!` ? I'm not even sure that is doing what you think. Instead of setting the values in the mutable array, it is setting the local variable (and creating a new matrix) every time. On Monday, August 24, 2015 at 7:31:56 PM UTC+2, Mohamed Moussa wrote: > > Hey. I'm new to Julia. I'm playing around with 0.4 on Windows. I'm > interested in writing finite element code for research purposes. > > Consider the following code > > function get_gauss_points!(gp_xi::Matrix) > gp_xi = [-1/sqrt(3) 1/sqrt(3) 1/sqrt(3) -1/sqrt(3); > -1/sqrt(3) -1/sqrt(3) 1/sqrt(3) 1/sqrt(3)] > end > > function get_gauss_points2!(gp_xi::Matrix) > gp_xi[1,1] = -1/sqrt(3) > gp_xi[2,1] = -1/sqrt(3) > gp_xi[1,2] = 1/sqrt(3) > gp_xi[2,2] = -1/sqrt(3) > gp_xi[1,3] = 1/sqrt(3) > gp_xi[2,3] = 1/sqrt(3) > gp_xi[1,4] = -1/sqrt(3) > gp_xi[2,4] = 1/sqrt(3) > end > > function test() > gp_xi = zeros(2,4) > get_gauss_points!(gp_xi) > get_gauss_points2!(gp_xi) > > println("get_gauss_points!:") > @time for i=1:1e7 get_gauss_points!(gp_xi) end > > println("\nget_gauss_points2!") > @time for i=1:1e7 get_gauss_points2!(gp_xi) end > end > > test() > > The output is > get_gauss_points!: > 1.129231 seconds (100.00 M allocations: 2.682 GB, 14.56% gc time) > > get_gauss_points2! > 0.067619 seconds > > Using @profile shows that get_gauss_points! spends a lot of time in > abstractarray. Is it possible to make get_gauss_points run as fast as > get_gauss_points2 ? > > Cheers. >
[julia-users] Re: Spped, assigning arrays
You'll want to study http://julialang.org/blog/2013/09/fast-numeric/ to figure out how to make your code faster. On Monday, August 24, 2015 at 10:31:56 AM UTC-7, Mohamed Moussa wrote: > > Hey. I'm new to Julia. I'm playing around with 0.4 on Windows. I'm > interested in writing finite element code for research purposes. > > Consider the following code > > function get_gauss_points!(gp_xi::Matrix) > gp_xi = [-1/sqrt(3) 1/sqrt(3) 1/sqrt(3) -1/sqrt(3); > -1/sqrt(3) -1/sqrt(3) 1/sqrt(3) 1/sqrt(3)] > end > > function get_gauss_points2!(gp_xi::Matrix) > gp_xi[1,1] = -1/sqrt(3) > gp_xi[2,1] = -1/sqrt(3) > gp_xi[1,2] = 1/sqrt(3) > gp_xi[2,2] = -1/sqrt(3) > gp_xi[1,3] = 1/sqrt(3) > gp_xi[2,3] = 1/sqrt(3) > gp_xi[1,4] = -1/sqrt(3) > gp_xi[2,4] = 1/sqrt(3) > end > > function test() > gp_xi = zeros(2,4) > get_gauss_points!(gp_xi) > get_gauss_points2!(gp_xi) > > println("get_gauss_points!:") > @time for i=1:1e7 get_gauss_points!(gp_xi) end > > println("\nget_gauss_points2!") > @time for i=1:1e7 get_gauss_points2!(gp_xi) end > end > > test() > > The output is > get_gauss_points!: > 1.129231 seconds (100.00 M allocations: 2.682 GB, 14.56% gc time) > > get_gauss_points2! > 0.067619 seconds > > Using @profile shows that get_gauss_points! spends a lot of time in > abstractarray. Is it possible to make get_gauss_points run as fast as > get_gauss_points2 ? > > Cheers. >