Using dpp on the openmpi headers

Peter Jacobs peterj at mech.uq.edu.au
Fri Mar 13 08:08:17 UTC 2020


Given the recent thread that mentioned dpp for generating an 
interface module for a C library, I thought that I would give it 
a go on the openmpi headers.  I am working in  LinuxMint system 
and after making a symbolic link for libclang.so, I have had some 
success but not complete success.

I have a module

// mpi.dpp

module mpi;

#include <mpi.h>

/**
  * Convert D's string[] args to a correct C char** argv.
  */
char** toArgv(string[] args)
{
     auto argv = new char*[args.length + 1];
     foreach(i, arg; args)
     {
         argv[i] = (arg.dup ~ '\0').ptr;
     }
     argv[args.length] = null;
     return argv.ptr;
}

enum MPI_DUMMY = 999;


a main module

// hello_d.d
// hacked out of the hello_d example from the OpenMPI project.

import std.stdio;
import std.string;
import std.array;
import std.algorithm;
import mpi;

int main(string[] args)
{
     int argc = cast(int)args.length;
     auto argv = args.toArgv();

     int rank;
     int size;
     writeln("MPI_VERSION=", MPI_VERSION);

     MPI_Init(&argc, &argv);
     //MPI_Comm_rank(MPI_COMM_WORLD, &rank);
     //MPI_Comm_size(MPI_COMM_WORLD, &size);
     writefln("Hello, world, I am %d of %d", rank+1, size);
     writeln("MPI_DUMMY=", MPI_DUMMY);
     //MPI_Barrier(MPI_COMM_WORLD);
     MPI_Finalize();

     return 0;
}

and a makefile

# makefile for hello_d, playing with dpp and MPI

hello_d : hello_d.d mpi.d
	dmd -ofhello_d hello_d.d mpi.d -L-lmpi

mpi.d : mpi.dpp
	dub run dpp -- --include-path=/usr/include/openmpi \
		--preprocess-only mpi.dpp

The dpp program successfully generates an interface module mpi.d 
and the hello_d executable is built and it runs.  However, not 
all of the needed elements for a real MPI program are present.  
For example, in the main module above, MPI_COMM_WORLD is not 
available so the lines calling MPI_Comm_rank, MPI_Comm_size and 
MPI_Barrier are commented out.

It may be that I am not using dpp correctly, however, running dpp 
with the -- option gives a lot output that includes

Cursor(MacroDefinition, "MPI_COMM_WORLD", Type(Invalid, "")) CAN 
@ SourceRange("/usr/include/openmpi/mpi.h", 1034:9, 1034:78)

so I am guessing that dpp does not know how to compute its type 
and value.

Thoughts or suggestions on how to proceed?





More information about the Digitalmars-d mailing list