diff --git a/examples/juliac/Makefile b/examples/juliac/Makefile new file mode 100644 index 000000000..47d609e19 --- /dev/null +++ b/examples/juliac/Makefile @@ -0,0 +1,27 @@ +JULIA ?= $(shell which julia) +JULIAC ?= $(shell $(JULIA) -e 'print(normpath(joinpath(Sys.BINDIR, Base.DATAROOTDIR, "julia", "juliac.jl")))') + +RUNIC_FILES := $(wildcard ../src/*.jl) ../Project.toml + +runicc: runicc.jl Project.toml Manifest.toml $(RUNIC_FILES) check-julia + $(JULIA) --project=. $(JULIAC) --verbose --output-exe $@ --experimental --trim=unsafe $< + +Manifest.toml: Project.toml ../Project.toml + $(JULIA) --project=. -e 'using Pkg; Pkg.instantiate()' + @touch $@ # Pkg.instantiate doesn't update the mtime if there are no changes + +clean: + -rm -f runicc Manifest.toml + +check-julia: + @if ! $(JULIA) --help-hidden | grep -s -q '\-\-trim'; then \ + echo "ERROR: The configured julia binary ($(JULIA)) does not support the --trim argument."; \ + echo " Configure the binary using the JULIA variable (e.g. \`JULIA=/path/to/julia make ...\`)"; \ + echo " or change how \`julia\` resolves in \`PATH\`."; \ + exit 1; \ + fi + +print-%: + @echo '$*=$($*)' + +.PHONY: clean check-julia diff --git a/examples/juliac/Project.toml b/examples/juliac/Project.toml new file mode 100644 index 000000000..ad3e09945 --- /dev/null +++ b/examples/juliac/Project.toml @@ -0,0 +1,5 @@ +[deps] +MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195" + +[sources] +MPI = {path = "../.."} diff --git a/examples/juliac/main.jl b/examples/juliac/main.jl new file mode 100644 index 000000000..d214e3c3b --- /dev/null +++ b/examples/juliac/main.jl @@ -0,0 +1,19 @@ +module MPIC + +# Compileable main function corresponding to `int main(int argc, char** argv)` +Base.@ccallable function main(argc::Cint, argv::Ptr{Ptr{UInt8}})::Cint + # Load command line arguments. Note that the first argument is the + # executable name so we skip it. + args = Vector{String}(undef, argc - 1) + for i in 2:argc + argptr = unsafe_load(argv, i) + arg = unsafe_string(argptr) + args[i - 1] = arg + end + return 0 +end + +# Tell juliac about the main entrypoint +Base.Experimental.entrypoint(main, (Cint, Ptr{Ptr{UInt8}})) + +end diff --git a/src/nonblocking.jl b/src/nonblocking.jl index 552129839..8013449fb 100644 --- a/src/nonblocking.jl +++ b/src/nonblocking.jl @@ -190,8 +190,17 @@ Base.unsafe_convert(::Type{MPI_Request}, request::Request) = request.val Base.unsafe_convert(::Type{Ptr{MPI_Request}}, request::Request) = convert(Ptr{MPI_Request}, pointer_from_objref(request)) -const REQUEST_NULL = Request(API.MPI_REQUEST_NULL[], nothing) -add_load_time_hook!(LoadTimeHookSetVal(REQUEST_NULL, API.MPI_REQUEST_NULL)) +struct NullRequest <: AbstractRequest end +const REQUEST_NULL = NullRequest() + +Base.convert(::Type{Request}, ::NullRequest) = + Request(API.MPI_REQUEST_NULL[], nothing) + +isnull(::NullRequest) = true +setbuffer!(::NullRequest, ::Any) = throw(ArgumentError("Cannot set buffer on NullRequest")) + +# const REQUEST_NULL = Request(API.MPI_REQUEST_NULL[], nothing) +# add_load_time_hook!(LoadTimeHookSetVal(REQUEST_NULL, API.MPI_REQUEST_NULL)) """ MPI.UnsafeRequest()