Пример #1
0
import os
os.environ["JULIA_PROJECT"] = "."

from julia.api import Julia
# ubuntu/debian/conda static linkage to libpython workaround
# set to True if you have a different python distribution
# otherwise it significantly bloats the initial loading time.
jl = Julia(compiled_modules=False)
from julia import Main

Main.include("src/BlueMesh7.jl")
jl.using(".BlueMesh7")
BlueMesh7 = Main.BlueMesh7

import numpy as np

positions = BlueMesh7.generate_positions()

node_roles = np.ones(len(positions), dtype='i8')
mesh = BlueMesh7.initialize_mesh(positions, node_roles)

print("running the simulation for 1 minute (60000 steps, 1 step = 1ms)...")
produced, received = BlueMesh7.start(mesh, minutes=1)
print(
    f"packets produced: {produced}, received: {received}, {round(100 * received / produced, 2)}%"
)
Пример #2
0
#
# WARNING: Before running this script, you must setup mpi4py and MPI.jl to use
# the SAME MPI library. This is described in the README.md found in the same
# directory as this script.

# Something in the below julia interface setup forks a process--setup julia before
# importing mpi4py to keep MPI from complaining about the fork
from julia.api import Julia
jl = Julia(compiled_modules=False)

import mpi4py
from mpi4py import MPI as pympi
comm = pympi.COMM_WORLD

# Activate the desired julia environment
jl.using("Pkg")
from julia import Pkg
Pkg.activate(".")

# Make julia global space available
from julia import Main

jl.using("MPI")
from julia import MPI as jlmpi

# Initialize Julia MPI without initializing the libmpi--this is part of the
# initialization done by MPI.Init() in MPI.jl
jl.eval(
    'function init_mpi(); for f in MPI.mpi_init_hooks; f(); end; return; end;')
Main.init_mpi()
Пример #3
0
# directory as this script.

# Something in the below julia interface setup forks a process--setup julia before
# importing mpi4py to keep MPI from complaining about the fork
from julia.api import Julia
jl = Julia(compiled_modules=False)

import mpi4py
from mpi4py import MPI as pympi

import numpy as np

comm = pympi.COMM_WORLD

# Activate the desired julia environment
jl.using('Pkg')
from julia import Pkg
Pkg.activate(".")

jl.using('MPI')
jl.using('Random')  # for seed! function
jl.using('Statistics')  # for mean function

from julia import Main
from julia import MPI as jlmpi

# Convert pympi comm to jlmpi comm
Main.handle = pympi._handleof(comm)  # make handle accessible to julia
jl.eval('comm = MPI.Comm(MPI.MPI_Comm(handle))')  # create julia comm

# WARNING: You might think that we could use a statement like
Пример #4
0
# WARNING: Before running this script, you must setup mpi4py and MPI.jl to use
# the SAME MPI library. This is described in the README.md found in the same
# directory as this script.

# Something in the below julia interface setup forks a process--setup julia before
# importing mpi4py to keep MPI from complaining about the fork
from julia.api import Julia
jl = Julia(compiled_modules=False)

import mpi4py
from mpi4py import MPI as pympi

import numpy as np

# Activate the desired julia environment
jl.using('Pkg')
from julia import Pkg
Pkg.activate(".")

jl.using('MPI')

from julia import Main
from julia import MPI as jlmpi

jl.eval('include("pi_func.jl")')
# Initialize jlmpi stuff without initializing libmpi again --
# function definition is in pi_func.jl
Main.init_mpi()

size = pympi.COMM_WORLD.Get_size()
if size > 1: