Skip to content

HPC-Delphi/mpi_delphi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mpi_delphi - MPI Library for Delphi Integration

Platform: Windows GCC MSMPI

mpi_delphi is a dynamic library written in C, providing distributed-memory parallelism using the standard Message Passing Interface (MPI) API for Delphi applications. It wraps Microsoft MPI (MSMPI) routines so Delphi projects can run coordinated multi-process workloads in High-Performance Computing (HPC) scenarios.

Features

  • Distributed-Memory Parallelism: Bridges Delphi with Microsoft MPI (MSMPI) for multi-process execution across ranks.
  • MPI Communication Primitives: Wraps point-to-point communication (blocking/non-blocking), collectives, and synchronization routines.
  • Delphi Wrapper: Includes a Delphi wrapper for seamless integration.
  • High-Performance Computing: Enables scalable distributed execution beyond single-process limits.
  • Cross-Language Compatibility: Distributed as a DLL, accessible from various programming environments.

Requirements & Development Environment

The library is developed, tested, and intended to be used in the following environment:

  • Operating System: Windows 11 (64-bit)
  • Compiler: GCC 15.1.0
  • Toolchain: MinGW-w64 12.0.0 UCRT (release 1) from winlibs.com
  • Dependencies: Microsoft MPI (MSMPI) SDK + Runtime 10.1.
  • Build System: mingw32-make
  • Delphi Integration: RAD Studio (Delphi 12.1 Community Edition)

Toolchain Setup and Installation Steps

To compile this library, you must install the GCC toolchain and MSMPI components. Follow these steps carefully:

1. Download the Correct Compiler Version

  • Navigate to winlibs.com.

  • Locate the block titled: "GCC 15.1.0 (with POSIX threads) + MinGW-w64 12.0.0 (UCRT) - release 1".

  • Under this block, look for the Win64 row (specifically: Win64 without LLVM/Clang/LLD/LLDB).

  • Click on 7-Zip archive (recommended for smaller download size) or Zip archive to download the package.

2. Extraction and Directory Setup

  • Extract the downloaded archive.

  • Move the extracted folder (usually named mingw64) to a clean, global system path without spaces (e.g.: C:\winlibs).

3. Add to Windows System Path
To call gcc and mingw32-make from any terminal, add the toolchain's bin directory to your system environment variables:

  • Press Win + S, type "env", and select Edit the system environment variables.

  • In the System Properties window, click on the Environment Variables... button.

  • Under System variables (bottom list), select the variable named Path and click Edit....

  • Click New on the right side and type the absolute path to the extracted bin directory:

    C:\winlibs\bin
    
  • Click OK to close each of the three setup windows

4. Install Microsoft MPI (MSMPI Runtime + SDK)

  • Download and install Microsoft MPI from: https://learn.microsoft.com/en-us/message-passing-interface/microsoft-mpi

  • Ensure both components are installed:

    • MSMPI Runtime
    • MSMPI SDK
  • Typical default install paths are:

    • C:\Program Files\Microsoft MPI\Bin (runtime: msmpi.dll, mpiexec.exe)
    • C:\Program Files (x86)\Microsoft SDKs\MPI\Include (mpi.h)
    • C:\Program Files (x86)\Microsoft SDKs\MPI\Lib\x64 (msmpi.lib)

5. Verification
Open a new Command Prompt (cmd) or PowerShell window and run the following commands:

gcc --version
mingw32-make --version
mpiexec -help

If configured correctly, these commands will return version/help information.

Project Structure

mpi_delphi/
│
├── build/                  # Compiled binaries and intermediate files
├── include/                # Public API headers (C)
│   └── mpi_delphi.h
├── interface/              # Delphi wrapper
│   └── MPI.pas
├── src/                    # C source code
│   └── mpi_delphi.c
├── LICENSE                 # License information
├── Makefile                # Build script for DLL
└── README.md               # Project documentation

Compilation Instructions

Once your toolchain environment is properly set up, building the library is simple:

  1. Open a terminal (Command Prompt or PowerShell).

  2. Ensure MSMPI include/lib variables are available in the session (typically set by SDK install):

    echo %MSMPI_INC%
    echo %MSMPI_LIB64%

    If empty, define them manually:

    set "MSMPI_INC=C:\Program Files (x86)\Microsoft SDKs\MPI\Include"
    set "MSMPI_LIB64=C:\Program Files (x86)\Microsoft SDKs\MPI\Lib\x64"
  3. Navigate to the root directory of this repository:

    cd path\to\mpi_delphi
  4. Run the compiler build tool:

    mingw32-make

This will generate mpi_delphi.dll in the build\ directory.

Using the Library in Delphi

1. Linking the DLL (Choose One Method)

To allow your Delphi application to load and communicate with the dynamic library, you must make mpi_delphi.dll discoverable by Windows. You can achieve this using one of the following methods:

Method A: Add the Build Directory to the System Path (Recommended for Development)
During active development of the C library, you might need to recompile the DLL frequently. Copying the file manually after every compilation is tedious and error-prone.

  1. Add the absolute path of your local mpi_delphi\build\ directory directly to your Windows system's PATH environment variable (following the same steps used for the compiler setup).

  2. Also ensure MSMPI runtime directory is in Path (typically C:\Program Files\Microsoft MPI\Bin).

Method B: Place the DLL in the Executable Folder (Recommended for Distribution)
If you are packaging, deploying, or sharing your compiled Delphi application:

  1. Locate your Delphi project's output directory (usually named Win64\Debug or Win64\Release inside your project's folder structure).

  2. Copy mpi_delphi.dll from mpi_delphi\build\ and paste it directly into that folder, alongside your compiled .exe file.

  3. You must also include required MSMPI runtime DLLs (or guarantee they are already installed and discoverable in Path).

2. Integrating the Wrapper in RAD Studio / Delphi

To use the library functions natively inside your Delphi Pascal source code, follow these steps:

  1. Open your Delphi project in RAD Studio.

  2. Go to the top menu and select Project > Options....

  3. In the left panel, navigate to Building > Delphi Compiler.

  4. In the main area, click the Search Path field.

  5. Click on the ellipsis ... button and add the absolute path to the interface\ folder inside your repository (e.g.: C:\Projects\mpi_delphi\interface).

  6. Click OK and then Save.

Example Usage:

uses MPI;

var
  rank, size: Integer;
begin
  MPI_Init;
  MPI_Comm_rank(@rank);
  MPI_Comm_size(@size);

  // Distributed logic based on 'rank' and 'size' goes here

  MPI_Finalize;
end;

Academic Citation

If you use this software in your research, please cite it using the metadata provided in the CITATION.cff file located in the root of this repository.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A dynamic library written in C that bridges Delphi applications with Microsoft MPI (MSMPI). It exposes standard Message Passing Interface (MPI) routines for distributed-memory parallelism, including point-to-point messaging and collective operations.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors