mpi :: mpi_simple
Serializable::inspect to show more useful information
			serialization :: serialization_core
Abstract services to serialize Nit objects to different formatsdeserialize_json and JsonDeserializer
			serialize_to_json and JsonSerializer
			core :: union_find
union–find algorithm using an efficient disjoint-set data structure
module mpi_simple is example
import mpi
# Simple class transfered between processors
class ProcessorInfo
	auto_serializable
	var rank: Int
	var size: Int
	var name: String
	var string_of_random_length: String
	init(mpi: MPI)
	do
		self.rank = comm_world.rank.to_i
		self.size = comm_world.size
		self.name = mpi.processor_name
		self.string_of_random_length = "+" * 10.rand
	end
	redef fun to_s do return "<{name}: {rank}/{size} {string_of_random_length}>"
end
var mpi = new MPI
var data = new CIntArray(2)
if comm_world.size == 1 then
	print "not enough nodes, got only 1"
	mpi.finalize
	exit 1
end
print "stdout: processor '{mpi.processor_name}' {comm_world.rank}/{comm_world.size}"
if comm_world.rank == 0.rank then
	# send - ints
	data[0] = 123
	data[1] = 456
	mpi.send_from(data, 0, 2, 1.rank, 0.tag, comm_world)
	# send - simple string
	mpi.send_all("Hello", 1.rank, 0.tag, comm_world)
	mpi.send_from(" World", 0, 6, 1.rank, 0.tag, comm_world)
	mpi.send_from("+-!0?", 2, 2, 1.rank, 0.tag, comm_world)
else if comm_world.rank == 1.rank then
	# recv - ints
	mpi.recv_into(data, 0, 2, 0.rank, 0.tag, comm_world)
	print "received data: {data[0]} {data[1]}"
	# recv - simple string
	var buf = new FlatBuffer.with_capacity(5)
	mpi.recv_fill(buf, 0.rank, 0.tag, comm_world)
	print "received string: {buf}"
	mpi.recv_into(buf, 5, 6, 0.rank, 0.tag, comm_world)
	print "received string: {buf}"
	mpi.recv_into(buf, 3, 2, 0.rank, 0.tag, comm_world)
	print "received string: {buf}"
end
# Passing complex objects and inverse sender/receiver
if comm_world.rank == 0.rank then
	var errors = 0
	var processors_per_host = new HashMap[String, Int]
	# recv - serializable
	for p in [1 .. comm_world.size[ do
		var a = mpi.recv(new Rank.any, 0.tag, comm_world)
		print "received serialized: {a or else "<null>"}"
		if a != null and a isa ProcessorInfo then
			if not processors_per_host.keys.has(a.name) then
				processors_per_host[a.name] = 1
			else processors_per_host[a.name] += 1
		else errors += 1
	end
	print "errors: {errors}"
	print "processors: {processors_per_host.join(", ", ": ")}"
else
	# send - serializable
	srand_from comm_world.rank.to_i
	var a = new ProcessorInfo(mpi)
	mpi.send(a, 0.rank, 0.tag, comm_world)
end
mpi.finalize
lib/mpi/examples/src/mpi_simple.nit:17,1--106,12