X-Git-Url: http://nitlanguage.org diff --git a/lib/mpi.nit b/lib/mpi.nit index 1d8c406..d7b5784 100644 --- a/lib/mpi.nit +++ b/lib/mpi.nit @@ -26,14 +26,14 @@ # Since this module is a thin wrapper around OpenMPI, in case of missing # documentation, you can refer to https://www.open-mpi.org/doc/v1.8/. module mpi is - c_compiler_option(exec("mpicc", "-showme:compile")) - c_linker_option(exec("mpicc", "-showme:link")) + cflags exec("mpicc", "-showme:compile") + ldflags exec("mpicc", "-showme:link") end import c intrude import standard::string import serialization -private import json_serialization +private import json::serialization in "C Header" `{ #include @@ -85,7 +85,7 @@ class MPI fun send(data: nullable Serializable, dest: Rank, tag: Tag, comm: Comm) do # Serialize data - var stream = new StringOStream + var stream = new StringWriter var serializer = new JsonSerializer(stream) serializer.serialize(data) @@ -117,7 +117,7 @@ class MPI # Deserialize message var deserializer = new JsonDeserializer(buffer) var deserialized = deserializer.deserialize - + if deserialized == null then print "|{buffer}|{buffer.chars.join("-")}| {buffer.length}" return deserialized @@ -177,33 +177,60 @@ extern class Comm `{ MPI_Comm `} # Number of processors in this communicator fun size: Int `{ int size; - MPI_Comm_size(recv, &size); + MPI_Comm_size(self, &size); return size; `} # Rank on this processor in this communicator fun rank: Rank `{ int rank; - MPI_Comm_rank(recv, &rank); + MPI_Comm_rank(self, &rank); return rank; `} end # An MPI data type extern class DataType `{ MPI_Datatype `} + # Get a MPI char. new char `{ return MPI_CHAR; `} + + # Get a MPI short. new short `{ return MPI_SHORT; `} + + # Get a MPI int. new int `{ return MPI_INT; `} + + # Get a MPI long. new long `{ return MPI_LONG; `} + + # Get a MPI long long. new long_long `{ return MPI_LONG_LONG; `} + + # Get a MPI unsigned char. new unsigned_char `{ return MPI_UNSIGNED_CHAR; `} + + # Get a MPI unsigned short. new unsigned_short `{ return MPI_UNSIGNED_SHORT; `} + + # Get a MPI unsigned int. new unsigned `{ return MPI_UNSIGNED; `} + + # Get a MPI unsigned long. new unsigned_long `{ return MPI_UNSIGNED_LONG; `} + + # Get a MPI unsigned long long. new unsigned_long_long `{ return MPI_UNSIGNED_LONG_LONG; `} + + # Get a MPI float. new float `{ return MPI_FLOAT; `} + + # Get a MPI double. new double `{ return MPI_DOUBLE; `} + + # Get a MPI long double. new long_double `{ return MPI_LONG_DOUBLE; `} + + # Get a MPI byte. new byte `{ return MPI_BYTE; `} end @@ -216,47 +243,86 @@ extern class Status `{ MPI_Status* `} new `{ return malloc(sizeof(MPI_Status)); `} # Source of this communication - fun source: Rank `{ return recv->MPI_SOURCE; `} + fun source: Rank `{ return self->MPI_SOURCE; `} # Tag of this communication - fun tag: Tag `{ return recv->MPI_TAG; `} + fun tag: Tag `{ return self->MPI_TAG; `} # Success or error on this communication - fun error: SuccessOrError `{ return recv->MPI_ERROR; `} + fun error: SuccessOrError `{ return self->MPI_ERROR; `} # Count of the given `data_type` in this communication fun count(data_type: DataType): Int `{ int count; - MPI_Get_count(recv, data_type, &count); + MPI_Get_count(self, data_type, &count); return count; `} end # An MPI operation # -# Used with the `reduce` method +# Used with the `reduce` method. +# +# See extern class Op `{ MPI_Op `} + # Get a MPI null operation. new op_null `{ return MPI_OP_NULL; `} + + # Get a MPI maximum operation. new max `{ return MPI_MAX; `} + + # Get a MPI minimum operation. new min `{ return MPI_MIN; `} + + # Get a MPI sum operation. new sum `{ return MPI_SUM; `} + + # Get a MPI product operation. new prod `{ return MPI_PROD; `} + + # Get a MPI logical and operation. new land `{ return MPI_LAND; `} + + # Get a MPI bit-wise and operation. new band `{ return MPI_BAND; `} + + # Get a MPI logical or operation. new lor `{ return MPI_LOR; `} + + # Get a MPI bit-wise or operation. new bor `{ return MPI_BOR; `} + + # Get a MPI logical xor operation. new lxor `{ return MPI_LXOR; `} + + # Get a MPI bit-wise xor operation. new bxor `{ return MPI_BXOR; `} + + # Get a MPI minloc operation. + # + # Used to compute a global minimum and also an index attached + # to the minimum value. + # + # See new minloc `{ return MPI_MINLOC; `} + + # Get a MPI maxloc operation. + # + # Used to compute a global maximum and also an index attached + # to the maximum value. + # + # See new maxloc `{ return MPI_MAXLOC; `} + + # Get a MPI replace operation. new replace `{ return MPI_REPLACE; `} end # An MPI return code to report success or errors extern class SuccessOrError `{ int `} # Is this a success? - fun is_success: Bool `{ return recv == MPI_SUCCESS; `} + fun is_success: Bool `{ return self == MPI_SUCCESS; `} # Is this an error? fun is_error: Bool do return not is_success @@ -267,14 +333,14 @@ extern class SuccessOrError `{ int `} fun error_class: ErrorClass `{ int class; - MPI_Error_class(recv, &class); + MPI_Error_class(self, &class); return class; `} redef fun to_s do return native_to_s.to_s private fun native_to_s: NativeString `{ char *err = malloc(MPI_MAX_ERROR_STRING); - MPI_Error_string(recv, err, NULL); + MPI_Error_string(self, err, NULL); return err; `} end @@ -284,7 +350,7 @@ extern class ErrorClass `{ int `} redef fun to_s do return native_to_s.to_s private fun native_to_s: NativeString `{ char *err = malloc(MPI_MAX_ERROR_STRING); - MPI_Error_string(recv, err, NULL); + MPI_Error_string(self, err, NULL); return err; `} end @@ -295,7 +361,7 @@ extern class Rank `{ int `} new any `{ return MPI_ANY_SOURCE; `} # This Rank as an `Int` - fun to_i: Int `{ return recv; `} + fun to_i: Int `{ return self; `} redef fun to_s do return to_i.to_s end @@ -305,19 +371,19 @@ extern class Tag `{ int `} new any `{ return MPI_ANY_TAG; `} # This tag as an `Int` - fun to_i: Int `{ return recv; `} + fun to_i: Int `{ return self; `} redef fun to_s do return to_i.to_s end redef universal Int # `self`th MPI rank - fun rank: Rank `{ return recv; `} + fun rank: Rank `{ return self; `} # Tag identified by `self` - fun tag: Tag `{ return recv; `} + fun tag: Tag `{ return self; `} # Is this value undefined according to MPI? (may be returned by `Status::count`) - fun is_undefined: Bool `{ return recv == MPI_UNDEFINED; `} + fun is_undefined: Bool `{ return self == MPI_UNDEFINED; `} end # Something sendable directly and efficiently over MPI