CPM: A software tool for Communication Performance Modelling

Test for model-based collectives

An example, showing how to work with communication models:

  • input of the model file
  • initialization and distribution of the model instance
  • invocation of the model-based collective
#include "config.h"
#include "collectives/cpm_coll.h"
#include <getopt.h>
#include <malloc.h>
#include <stdio.h>

int main(int argc, char** argv) {
    MPI_Init(&argc, &argv);
    Hockney_model* model = NULL;
    int rank, size;
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);
    if (rank == 0) {
        int c;
        if ((c = getopt (argc, argv, "i:")) != -1) {
            switch (c) {
            case 'i': {
                FILE* file = fopen(optarg, "r");
                if (file == NULL)
                    fprintf(stderr, "Cannot read input file %s\n", optarg);
                else {
                    Hockney_read(file, &model);
                    fclose(file);
                }
                break;
            }
            }
        }
        else{
            fprintf(stderr, "You must specify an input argument\n");
        }
    }
    int exit = model == NULL;
    MPI_Bcast(&exit, 1, MPI_INT, 0, MPI_COMM_WORLD);
    if (exit) {
        MPI_Finalize();
        return 0;
    }
    Hockney_initialize(MPI_COMM_WORLD, model);
    if (rank == 0)
        Hockney_free(model);
    int count = 1024;
    char* buffer = (char*)malloc(sizeof(char) * count);
    Hockney_Bcast_ucs_binomial_min(buffer, count, MPI_CHAR, 0, MPI_COMM_WORLD);
    free(buffer);
    Hockney_finalize(MPI_COMM_WORLD);
    MPI_Finalize();
    return 0;
}