fupermod: Functional Performance Models of heterogeneous processors

Template for computational routines

#include "config.h"
#include <mpi.h>
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char** argv) {
    MPI_Init(&argc, &argv);
    MPI_Comm comm = MPI_COMM_WORLD;

    // exit routine
    int exit = 0;

    // Options
    int n = 100;

    int root = 0;
    int rank;
    MPI_Comm_rank(comm, &rank);
    if (rank == root) {
        int opt;
        while ((opt = getopt(argc, argv, "h:n:")) != -1)
            switch(opt) {
                case 'h':
                    fprintf(
                            stderr,
                            "template routine\n"
                            "Usage: [options]\n"
                            "   -h      help\n"
                            "   -n I    option (default %d)\n",
                            n
                    );
                    exit = 1;
                    break;
                case 'n':
                    n = atoi(optarg);
                    break;
                default:
                    fprintf(stderr, "Unknown option %s\n", optarg);
                    break;
            }
    }

    MPI_Bcast(&exit, 1, MPI_INT, root, comm);
    if (exit) {
        MPI_Finalize();
        return 0;
    }

    MPI_Bcast(&n, 1, MPI_INT, root, comm);
    /*
    *   Here should be executable code where kernel is main component. 
    * */
    MPI_Finalize();
    return 0;
}
See also:
Template for computational kernels