Skip to content

Initial stab at JuliaC trimmability - #994

Open
cmhamel wants to merge 1 commit into
JuliaParallel:masterfrom
cmhamel:master
Open

cmhamel wants to merge 1 commit into
JuliaParallel:masterfrom
cmhamel:master

Conversation

@cmhamel

@cmhamel cmhamel commented Oct 3, 2026 •

Copy link
Copy Markdown

Reworking how init and load time hooks are handled to allow for JuliaC trim safety.

  • An environment flag called JULIA_MPI_TRIM_SAFE is introduced to branch in parts of the package that aren't trimmable.
  • Each file that had exisiting add_load_time_hook! and add_init_hook! methods have a new method called _setup_load_time_<file_name> rather than relying on the module level arrays of hooks which caused juliac errors under trim.

With these changes I was able to compile the following program into a 2.7Mb binary that works!

using MPI

function @main(ARGS)
    MPI.Init()
    comm = MPI.COMM_WORLD
    rank = MPI.Comm_rank(comm)
    size = MPI.Comm_size(comm)
    print(Core.stdout, "Hello world, I am rank $(MPI.Comm_rank(comm)) of $(MPI.Comm_size(comm))\n")

    N = 5
    root = 0

    if MPI.Comm_rank(comm) == root
        print(Core.stdout, " Running on $(MPI.Comm_size(comm)) processes\n")
    end
    MPI.Barrier(comm)

    if MPI.Comm_rank(comm) == root
        A = [i*(1.0 + im*2.0) for i = 1:N]
    else
        A = Array{ComplexF64}(undef, N)
    end

    MPI.Bcast!(A, root, comm)

    dst = mod(rank+1, size)
    src = mod(rank-1, size)

    N = 4

    send_mesg = Array{Float64}(undef, N)
    recv_mesg = Array{Float64}(undef, N)

    fill!(send_mesg, Float64(rank))

    rreq = MPI.Irecv!(recv_mesg, comm; source=src, tag=src+32)

    sreq = MPI.Isend(send_mesg, comm; dest=dst, tag=rank+32)

    stats = MPI.Waitall([rreq, sreq])

    MPI.Finalize()
    return 0
end

Here is the set of JuliaC commands I used

using JuliaC
build_path = joinpath(@__DIR__, "build")
src_path = joinpath(@__DIR__)
@show build_path
@show src_path
rm(build_path; force=true, recursive=true)

img = ImageRecipe(
    output_type    = "--output-exe",
    file           = "$src_path/src/MyApp.jl",
    trim_mode      = "safe",
    add_ccallables = false,
    verbose        = false,
)

link = LinkRecipe(
    image_recipe = img,
    outname      = "$build_path/my_app"
)

bun = BundleRecipe(
    link_recipe = link,
    output_dir  = build_path # or `nothing` to skip bundling
)

compile_products(img)
link_products(link)
bundle_products(bun)

which I built with

JULIA_MPI_TRIM_SAFE=true julia +1.12 --project=@. make.jl

I have not tried to test every function within the package. I view this as an initial push towards allowing for MPI aware small binaries.

The test suite passes locally as well as the test suite for PartitionedArrays

This addresses issue #931.

…C trim safety. An environment flag called JULIA_MPI_TRIM_SAFE is introduced to branch in parts of the package that aren't trimmable. This addresses issue JuliaParallel#931.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant