Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// swift-tools-version:5.0

/*
* This file is part of COpenMPI.
*
Expand All @@ -18,9 +20,30 @@
import PackageDescription

let package = Package(
name: "COpenMPI",
pkgConfig: "ompi-c",
providers: [
.Brew("open-mpi")
]
name: "COpenMPI",
products: [
.library(
name: "COpenMPI",
targets: ["CMPI"]
),
.executable(
name: "COpenMPI-Example",
targets: ["COpenMPI-Example"]
)
],
targets: [
.systemLibrary(
name: "CMPI",
pkgConfig: "ompi-c",
providers: [
.brew(["open-mpi"])
]
),
.target(
name: "COpenMPI-Example",
dependencies: [
"CMPI"
]
)
]
)
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,12 @@ The package exports a single module, `CMPI`.
Due to the use of function-like macros in `mpi.h`, a shim header that wraps these is required. `shim.h` creates inline functions for the constants and maps them to read-only global computed properties.

A simple MPI program (à la '[Hello World](http://mpitutorial.com/tutorials/mpi-hello-world/)') appears to work correctly, but this has not been extensively tested. Feedback is requested!

## Example

An example of using the library is included. To clone and run the example run the following commands in Terminal.

1. `git clone https://github.com/omor1/COpenMPI.git`
2. `cd COpenMPI`
3. `swift build -c release`
4. `mpirun -c 2 .build/*/release/COpenMPI-Example`
File renamed without changes.
File renamed without changes.
62 changes: 62 additions & 0 deletions Sources/COpenMPI-Example/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* This file is part of COpenMPI.
*
* COpenMPI is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* COpenMPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with COpenMPI. If not, see <http://www.gnu.org/licenses/>.
*/

import CMPI

var argc = CommandLine.argc
var argv: UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>? = CommandLine.unsafeArgv

MPI_Init(&argc, &argv)

var worldSize = Int32()
MPI_Comm_size(MPI_COMM_WORLD, &worldSize)

var worldRank = Int32()
MPI_Comm_rank(MPI_COMM_WORLD, &worldRank)

if (worldRank == 0) {
var majorVersion = Int32()
var minorVersion = Int32()

MPI_Get_version(&majorVersion, &minorVersion)

var cLibraryVersion = [CChar](repeating: 0, count: Int(MPI_MAX_LIBRARY_VERSION_STRING))
var libraryVersionResultLen = Int32()

MPI_Get_library_version(&cLibraryVersion, &libraryVersionResultLen)

let libraryVersion = withUnsafePointer(to: &cLibraryVersion[0]) {
return String(cString: $0)
}

print("MPI Version: \(majorVersion).\(minorVersion), \(libraryVersion)\n")
}

MPI_Barrier(MPI_COMM_WORLD)

var cProcessorName = [CChar](repeating: 0, count: Int(MPI_MAX_PROCESSOR_NAME))
var processorNameResultLen = Int32()

MPI_Get_processor_name(&cProcessorName, &processorNameResultLen)

let processorName = withUnsafePointer(to: &cProcessorName[0]) {
return String(cString: $0)
}

print("👋🗺 World Rank: \(worldRank), World Size: \(worldSize), Processor Name: \(processorName)")

MPI_Finalize()