1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
extern crate libc;

use std::env::Args;
use libc::{ptrdiff_t, size_t, c_int, c_char};
use libc::{c_longlong, c_void, c_uint, c_double};

pub mod request;
pub mod bindings;
pub mod comm;
pub mod error;
pub mod status;

use bindings::*;

/*
pub fn init(argc: usize, argv: Vec<Args>) -> () {
  unsafe { ffi::MPI_Init(&argc as *mut c_int, argv) } //TODO: howdoi?
}
*/

/// Calls MPI_Init with null parameters.
/// As of MPI-2, MPI_Init will accept NULL as input parameters.
/// Must be called before any other mpi function is called.
/// # Panics
/// When called multiple times.
/// When called without finalize at end of program.
/// # Examples
/// ```
/// // Valid
/// init_null();
/// finalize();
///
/// // Invalid
/// init_null();
/// init_null();
/// finalize();
///
/// // Invalid without finalize
/// init_null();
/// ```
pub fn init_null() -> i32 {
  let argc = 0 as *mut c_int;
  let argv = 0 as *mut *mut *mut c_char;
  unsafe { MPI_Init(argc, argv) }
}

/// Cleans up mpi stuff. Should always return success, no need for Error.
/// # Panics
/// When called multiple times.
/// When called without init.
/// # Examples
/// ```
/// // Valid
/// init_null();
/// finalize();
///
/// // Invalid
/// init_null();
/// finalize();
/// finalize();
///
/// // Invalid without init
/// finalize();
/// ```
pub fn finalize() -> () {
  let _ = unsafe { MPI_Finalize() };
}