-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added basic setup for mpi * Passed fmt * Added compilation test * Updated type * Passed fmt * Added MPI wrapper * Removed some declarations * Updated headers * Updated mpi wrapper * Updated file name * Updated MPI * Updated la
- Loading branch information
1 parent
4f7b948
commit f2972f5
Showing
15 changed files
with
532 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Message Passing Interface for parallel computing | ||
|
||
The `mpi` package is a light wrapper to the [OpenMPI](https://www.open-mpi.org) C++ library designed | ||
to develop algorithms for parallel computing. | ||
|
||
This package allows parallel computations over the network. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module mpi | ||
|
||
#flag linux -I/usr/lib/x86_64-linux-gnu/openmpi/include/openmpi -I/usr/lib/x86_64-linux-gnu/openmpi/include -pthread -I@VMODROOT | ||
#flag linux -pthread -L/usr/lib/x86_64-linux-gnu/openmpi/lib -lmpi | ||
#flag darwin -I/usr/local/Cellar/open-mpi/4.0.1_2/include -I@VMODROOT | ||
#flag darwin -L/usr/local/opt/libevent/lib -L/usr/local/Cellar/open-mpi/4.0.1_2/lib -lmpi | ||
#flag freebsd -I/usr/local/include -I@VMODROOT | ||
#flag freebsd -L/usr/local/lib -lmpi | ||
|
||
#include <cmpi.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#ifndef V_MPI_H | ||
#define V_MPI_H | ||
|
||
#include "mpi.h" | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
module main | ||
|
||
import vsl.float.float64 | ||
import vsl.mpi | ||
|
||
fn example() ? { | ||
mpi.start()? | ||
|
||
defer { | ||
mpi.stop() | ||
} | ||
|
||
if mpi.world_rank() == 0 { | ||
println('Test MPI 01') | ||
} | ||
|
||
println('Hello from rank $mpi.world_rank()') | ||
println('The world has $mpi.world_size() processes') | ||
|
||
n := 11 | ||
mut x := []f64{len: n} | ||
id, sz := mpi.world_rank(), mpi.world_size() | ||
start, endp1 := (id * n) / sz, ((id + 1) * n) / sz | ||
for i := start; i < endp1; i++ { | ||
x[i] = f64(i) | ||
} | ||
|
||
// Communicator | ||
comm := mpi.new_communicator([])? | ||
|
||
// Barrier | ||
comm.barrier() | ||
|
||
// sum to root | ||
mut r := []f64{len: n} | ||
comm.reduce_sum(mut r, x) | ||
if id == 0 { | ||
assertion := float64.arrays_tolerance(r, []f64{len: n, init: it}, 1e-17) | ||
println('ID: $id - Assertion: $assertion') | ||
} else { | ||
assertion := float64.arrays_tolerance(r, []f64{len: n}, 1e-17) | ||
println('ID: $id - Assertion: $assertion') | ||
} | ||
|
||
r[0] = 123.0 | ||
comm.bcast_from_root(r) | ||
assertion := float64.arrays_tolerance(r, [123.0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 1e-17) | ||
println('ID: $id - Assertion: $assertion') | ||
} | ||
|
||
fn main() { | ||
example() or { panic(err) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
module mpi | ||
|
||
import vsl.errors | ||
import math.complex | ||
|
||
// is_on tells whether MPI is on or not | ||
// note: this returns true even after stop | ||
pub fn is_on() bool { | ||
return false | ||
} | ||
|
||
// start initialises MPI | ||
pub fn start() ? { | ||
return errors.error('MPI is not supported on this platform', .efailed) | ||
} | ||
|
||
// stop finalises MPI | ||
pub fn stop() { | ||
} | ||
|
||
// world_rank returns the processor rank/ID within the World Communicator | ||
pub fn world_rank() int { | ||
return 0 | ||
} | ||
|
||
// world_size returns the number of processors in the World Communicator | ||
pub fn world_size() int { | ||
return 0 | ||
} | ||
|
||
// Communicator holds the World Communicator or a subset Communicator | ||
pub struct Communicator {} | ||
|
||
// new_communicator creates a new communicator or returns the World Communicator | ||
// ranks -- World indices of processors in this Communicator. | ||
// use nil or empty to get the World Communicator | ||
pub fn new_communicator(ranks []int) ?&Communicator { | ||
return errors.error('MPI is not supported on this platform', .efailed) | ||
} | ||
|
||
// rank returns the processor rank/ID | ||
pub fn (o &Communicator) rank() int { | ||
return 0 | ||
} | ||
|
||
// size returns the number of processors | ||
pub fn (o &Communicator) size() int { | ||
return 0 | ||
} | ||
|
||
// abort aborts MPI | ||
pub fn (o &Communicator) abort() { | ||
} | ||
|
||
// barrier forces synchronisation | ||
pub fn (o &Communicator) barrier() { | ||
} | ||
|
||
// bcast_from_root broadcasts slice from root (Rank == 0) to all other processors | ||
pub fn (o &Communicator) bcast_from_root(x []f64) { | ||
} | ||
|
||
// bcast_from_root_c broadcasts slice from root (Rank == 0) to all other processors (complex version) | ||
pub fn (o &Communicator) bcast_from_root_c(x []complex.Complex) { | ||
} | ||
|
||
// reduce_sum sums all values in 'orig' to 'dest' in root (Rank == 0) processor | ||
// note (important): orig and dest must be different slices | ||
pub fn (o &Communicator) reduce_sum(mut dest []f64, orig []f64) { | ||
} | ||
|
||
// reduce_sum_c sums all values in 'orig' to 'dest' in root (Rank == 0) processor (complex version) | ||
// note (important): orig and dest must be different slices | ||
pub fn (o &Communicator) reduce_sum_c(mut dest []complex.Complex, orig []complex.Complex) { | ||
} | ||
|
||
// all_reduce_sum combines all values from orig into dest summing values | ||
// note (important): orig and dest must be different slices | ||
pub fn (o &Communicator) all_reduce_sum(mut dest []f64, orig []f64) { | ||
} | ||
|
||
// all_reduce_sum_c combines all values from orig into dest summing values (complex version) | ||
// note (important): orig and dest must be different slices | ||
pub fn (o &Communicator) all_reduce_sum_c(mut dest []complex.Complex, orig []complex.Complex) { | ||
} | ||
|
||
// all_reduce_min combines all values from orig into dest picking minimum values | ||
// note (important): orig and dest must be different slices | ||
pub fn (o &Communicator) all_reduce_min(mut dest []f64, orig []f64) { | ||
} | ||
|
||
// all_reduce_max combines all values from orig into dest picking minimum values | ||
// note (important): orig and dest must be different slices | ||
pub fn (o &Communicator) all_reduce_max(mut dest []f64, orig []f64) { | ||
} | ||
|
||
// all_reduce_min_i combines all values from orig into dest picking minimum values (integer version) | ||
// note (important): orig and dest must be different slices | ||
pub fn (o &Communicator) all_reduce_min_i(mut dest []int, orig []int) { | ||
} | ||
|
||
// all_reduce_max_i combines all values from orig into dest picking minimum values (integer version) | ||
// note (important): orig and dest must be different slices | ||
pub fn (o &Communicator) all_reduce_max_i(mut dest []int, orig []int) { | ||
} | ||
|
||
// send sends values to processor toID | ||
pub fn (o &Communicator) send(vals []f64, to_id int) { | ||
} | ||
|
||
// recv receives values from processor fromId | ||
pub fn (o &Communicator) recv(vals []f64, from_id int) { | ||
} | ||
|
||
// send_c sends values to processor toID (complex version) | ||
pub fn (o &Communicator) send_c(vals []complex.Complex, to_id int) { | ||
} | ||
|
||
// recv_c receives values from processor fromId (complex version) | ||
pub fn (o &Communicator) recv_c(vals []complex.Complex, from_id int) { | ||
} | ||
|
||
// send_i sends values to processor toID (integer version) | ||
pub fn (o &Communicator) send_i(vals []int, to_id int) { | ||
} | ||
|
||
// recv_i receives values from processor fromId (integer version) | ||
pub fn (o &Communicator) recv_i(vals []int, from_id int) { | ||
} | ||
|
||
// send_one sends one value to processor toID | ||
pub fn (o &Communicator) send_one(val f64, to_id int) { | ||
} | ||
|
||
// recv_one receives one value from processor fromId | ||
pub fn (o &Communicator) recv_one(from_id int) f64 { | ||
return 0 | ||
} | ||
|
||
// send_one_i sends one value to processor toID (integer version) | ||
pub fn (o &Communicator) send_one_i(val int, to_id int) { | ||
} | ||
|
||
// recv_one_i receives one value from processor fromId (integer version) | ||
pub fn (o &Communicator) recv_one_i(from_id int) int { | ||
return 0 | ||
} |
Oops, something went wrong.