Le mardi 24 février 2015 à 05:25 -0800, Bill Hart a écrit : > In answer to your original question, assuming you had a very complex C > program that Julia just didn't handle efficiently (it's possible), or > you had already written a very large external library which you didn't > want to rewrite in Julia, and someone else hasn't already written an > interface to it from Julia.... > > > First you want to make a shared library. For this you can use gcc. > First compile your C file to an object file with the -c option. Then > link your object file to make a shared library with the -shared > option. This will make a shared library (.so or .dll or .dylib, > depending on what operating system you have). > > > It's the .so or .dll or .dylib file that Julia wants to be able to > find, not the C file. > > > So long as your shared library has no other dependencies, you can set > Julia's DL_LOAD_PATH to specify the location of the shared library > (I'm not sure if this is considered best practice or not). > > > Otherwise, on most systems the dynamic linker has various places it > will look for your library. This depends on your system though, so it > varies between Unix, Linux, Windows and OSX. This should work, but I think the "best practice" if you need to make your code public at some point is to use BinDeps, as explained in the thread I linked to. Though if you're the only one to work on it, a few hacks to build and locate the library might be enough.
Regards > On Tuesday, 24 February 2015 14:10:31 UTC+1, Bill Hart wrote: > One important thing to note is that if you do a + b at the top > level, it won't be fast. > > > But as soon as you do a + b inside a function, it will be as > fast as C. > > For example > > > a = 20 > b = 10 > for i = 1:1000000000 > c = a + b > end > > > takes about 34s > > > But the following is almost instantaneous: > > > function doit() > a = 20 > b = 10 > for i = 1:1000000000 > c = a + b > end > end > > > doit() > > > On Tuesday, 24 February 2015 14:03:07 UTC+1, Tim Holy wrote: > Giovanni, > > Before you start going to that kind of effort, take a > look at > > julia> @code_native 3+5 > .text > Filename: int.jl > Source line: 12 > push RBP > mov RBP, RSP > Source line: 12 > add RDI, RSI > mov RAX, RDI > pop RBP > ret > > I think you're going to have a pretty hard time > finding a C compiler that does > better than this :-). Especially since it gets inlined > at the call site. > > Best, > --Tim > > On Tuesday, February 24, 2015 01:13:52 AM > [email protected] wrote: > > Hello, > > > > I am a beginner to Julia and would like to try out > some features. I would > > like to improve performances of some bottleneck > functions by translating > > them into C. > > A simple example is : > > main.jl > > > > a ::Int64 = 20 > > b ::Int64 = 10 > > ccall(:do_sum, Int64, (Int64, Int64), a, b) > > > > > > > > test.c > > #include <stdio.h> > > > > int do_sum (int a,int b) > > { > > int c; > > c = a+b; > > printf("f\n:",c); > > return c; > > } > > > > where should I put the C file ? > > > > Thanks, > > G. >
