Skip to content

Commit 0e72c85

Browse files
timholyJeffBezanson
authored andcommitted
Get lib example working, create build script (#55104)
Note this is a PR against #55047 Co-authored by: Gabriel Baraldi <[email protected]>
1 parent 9350a06 commit 0e72c85

File tree

5 files changed

+37
-71
lines changed

5 files changed

+37
-71
lines changed

juliac/lib_examples/liblinsolve.jl

Lines changed: 0 additions & 69 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[deps]
2+
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
3+
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
4+
OpenBLAS_jll = "4536629a-c528-5b80-bd46-f80d51c5b363"
5+
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
6+
RecursiveFactorization = "f2c3362d-daeb-58d1-803e-2bc74f2840b4"
7+
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
8+
Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3"
9+
StrideArraysCore = "7792a7ef-975c-4747-a70f-980b88e8d1da"

juliac/lib_examples/linsolve/build.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#! /bin/bash
2+
if [ ! -f Manifest.toml ]; then
3+
echo "Instantiating package environment..."
4+
../../../julia --project -e 'using Pkg; Pkg.instantiate()'
5+
echo "done"
6+
fi
7+
echo "Building library..."
8+
../../../julia --project ../../juliac.jl --output-lib liblinsolve --compile-ccallable --static-call-graph liblinsolve.jl
9+
echo "done"
10+
echo "Linking C main..."
11+
gcc -o linsolve10 -L. -Wl,-rpath,\$ORIGIN ../../test/test.c -llinsolve
12+
echo "done"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module Lib
2+
3+
using LinearAlgebra
4+
5+
Base.@ccallable function linsolve10(A_ptr::Ptr{Float64}, b_ptr::Ptr{Float64}, N::Csize_t)::Ptr{Float64}
6+
A = unsafe_wrap(Array, A_ptr, (N,N))
7+
b = unsafe_wrap(Array, b_ptr, N)
8+
F = lu!(A)
9+
ldiv!(F, b)
10+
return b_ptr
11+
end
12+
13+
end

juliac/test/test.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <stdio.h>
22

3-
double* linsolve10(double *A, double *b);
3+
double* linsolve10(double * A, double * b, size_t N);
4+
45
int main() {
56
// Declare a 10x10 matrix
67
double A[10][10] = {
@@ -27,7 +28,7 @@ int main() {
2728
-10.107200370651855,
2829
0.8478731362967014};
2930

30-
linsolve10(A, b);
31+
linsolve10((double*)A, (double*)b, 10);
3132
for (int i = 0; i < 10; i++) {
3233
printf("%f\n", b[i]);
3334
}

0 commit comments

Comments
 (0)