Created
May 18, 2021 23:28
-
-
Save staticfloat/2ca67593a92f77b1568c03ea47933e36 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
/* DGESV prototype */ | |
extern void DGESV( int* n, int* nrhs, double* a, int* lda, int* ipiv, | |
double* b, int* ldb, int* info ); | |
/* Main program */ | |
int main() { | |
/* Locals */ | |
int n = 10000, info; | |
/* Local arrays */ | |
/* Initialization */ | |
double *a = malloc(n*n*sizeof(double)); | |
double *b = malloc(n*n*sizeof(double)); | |
int *ipiv = malloc(n*sizeof(int)); | |
for (int i = 0; i < n*n; i++ ) | |
{ | |
a[i] = ((double) rand()) / ((double) RAND_MAX) - 0.5; | |
} | |
for(int i=0;i<n*n;i++) | |
{ | |
b[i] = ((double) rand()) / ((double) RAND_MAX) - 0.5; | |
} | |
/* Solve the equations A*X = B */ | |
DGESV( &n, &n, a, &n, ipiv, b, &n, &info ); | |
free(a); | |
free(b); | |
free(ipiv); | |
exit( 0 ); | |
} /* End of DGESV Example */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
build: dgesv_accelerate dgesv_openblas | |
dgesv_accelerate: dgesv.c | |
clang -o $@ -DDGESV=dgesv $< -framework Accelerate | |
lib: | |
mkdir -p $@ | |
lib/libgfortran.dylib: | lib | |
curl -L https://github.com/JuliaBinaryWrappers/CompilerSupportLibraries_jll.jl/releases/download/CompilerSupportLibraries-v0.4.3%2B0/CompilerSupportLibraries.v0.4.3.aarch64-apple-darwin-libgfortran5.tar.gz | tar -zxv lib/libg*.dylib | |
lib/libopenblas.dylib: lib/libgfortran.dylib | lib | |
curl -L https://github.com/JuliaBinaryWrappers/OpenBLAS32_jll.jl/releases/download/OpenBLAS32-v0.3.13%2B3/OpenBLAS32.v0.3.13.aarch64-apple-darwin-libgfortran5.tar.gz | tar -zxv lib/libopenblas*.dylib | |
dgesv_openblas: dgesv.c lib/libopenblas.dylib | |
clang -o $@ -DDGESV=dgesv_ $< -lopenblas -L./lib -Wl,-rpath,@loader_path/lib | |
timing_solo: build | |
@echo " -> First, Accelerate on its own:" | |
time ./dgesv_accelerate | |
@echo " -> Second, OpenBLAS on its own: (using 4 threads, so we only get scheduled on performance cores)" | |
OPENBLAS_NUM_THREADS=4 time ./dgesv_openblas | |
timing_oversubscribed: build | |
@echo " -> Next, two Accelerates: (should be 2x the time of Accelerate)" | |
./dgesv_accelerate & ./dgesv_accelerate & time wait | |
@echo " -> Next, one Accelerate in the background with 4-core OpenBLAS running in the foreground:" | |
./dgesv_accelerate & OPENBLAS_NUM_THREADS=4 time ./dgesv_openblas | |
timing_optimal: build | |
@echo " -> OpenBLAS on its own: (using 3 threads, sowe leave one performance core open)" | |
OPENBLAS_NUM_THREADS=3 time ./dgesv_openblas | |
@echo " -> Finally, one Accelerate in the background with 3-core OpenBLAS running in the foreground:" | |
./dgesv_accelerate & OPENBLAS_NUM_THREADS=3 time ./dgesv_openblas |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment