|
Packit Service |
c5cf8c |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* (C) 2012 by Argonne National Laboratory.
|
|
Packit Service |
c5cf8c |
* See COPYRIGHT in top-level directory.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* Tests that basic optimizations are performed on indexed datatypes.
|
|
Packit Service |
c5cf8c |
*
|
|
Packit Service |
c5cf8c |
* If PACK_IS_NATIVE is defined, MPI_Pack stores exactly the same bytes as the
|
|
Packit Service |
c5cf8c |
* user would pack manually; in that case, there is a consistency check.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#ifdef MPICH
|
|
Packit Service |
c5cf8c |
/* MPICH (as of 6/2012) packs the native bytes */
|
|
Packit Service |
c5cf8c |
#define PACK_IS_NATIVE
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#include "mpi.h"
|
|
Packit Service |
c5cf8c |
#include "mpitest.h"
|
|
Packit Service |
c5cf8c |
#include <stdio.h>
|
|
Packit Service |
c5cf8c |
#include <stdlib.h>
|
|
Packit Service |
c5cf8c |
#include <string.h>
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
static int verbose = 0;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
int main(int argc, char **argv)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
double *inbuf, *outbuf, *outbuf2;
|
|
Packit Service |
c5cf8c |
MPI_Aint lb, extent;
|
|
Packit Service |
c5cf8c |
int *index_displacement;
|
|
Packit Service |
c5cf8c |
int icount, errs = 0;
|
|
Packit Service |
c5cf8c |
int i, packsize, position, inbufsize;
|
|
Packit Service |
c5cf8c |
MPI_Datatype itype1, stype1;
|
|
Packit Service |
c5cf8c |
double t0, t1;
|
|
Packit Service |
c5cf8c |
double tpack, tspack, tmanual;
|
|
Packit Service |
c5cf8c |
int ntry;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MTest_Init(&argc, &argv);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
icount = 2014;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Create a simple block indexed datatype */
|
|
Packit Service |
c5cf8c |
index_displacement = (int *) malloc(icount * sizeof(int));
|
|
Packit Service |
c5cf8c |
if (!index_displacement) {
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "Unable to allocated index array of size %d\n", icount);
|
|
Packit Service |
c5cf8c |
MPI_Abort(MPI_COMM_WORLD, 1);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
for (i = 0; i < icount; i++) {
|
|
Packit Service |
c5cf8c |
index_displacement[i] = (i * 3 + (i % 3));
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Type_create_indexed_block(icount, 1, index_displacement, MPI_DOUBLE, &itype1);
|
|
Packit Service |
c5cf8c |
MPI_Type_commit(&itype1);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#if defined(MPICH) && defined(PRINT_DATATYPE_INTERNALS)
|
|
Packit Service |
c5cf8c |
/* To use MPIR_Datatype_debug to print the datatype internals,
|
|
Packit Service |
c5cf8c |
* you must configure MPICH with --enable-g=log */
|
|
Packit Service |
c5cf8c |
if (verbose) {
|
|
Packit Service |
c5cf8c |
printf("Block index datatype:\n");
|
|
Packit Service |
c5cf8c |
MPIR_Datatype_debug(itype1, 10);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
MPI_Type_get_extent(itype1, &lb, &extent);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Pack_size(1, itype1, MPI_COMM_WORLD, &packsize);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
inbufsize = extent / sizeof(double);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
inbuf = (double *) malloc(extent);
|
|
Packit Service |
c5cf8c |
outbuf = (double *) malloc(packsize);
|
|
Packit Service |
c5cf8c |
outbuf2 = (double *) malloc(icount * sizeof(double));
|
|
Packit Service |
c5cf8c |
if (!inbuf) {
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "Unable to allocate %ld for inbuf\n", (long) extent);
|
|
Packit Service |
c5cf8c |
MPI_Abort(MPI_COMM_WORLD, 1);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (!outbuf) {
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "Unable to allocate %ld for outbuf\n", (long) packsize);
|
|
Packit Service |
c5cf8c |
MPI_Abort(MPI_COMM_WORLD, 1);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (!outbuf2) {
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "Unable to allocate %ld for outbuf2\n", (long) packsize);
|
|
Packit Service |
c5cf8c |
MPI_Abort(MPI_COMM_WORLD, 1);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
for (i = 0; i < inbufsize; i++) {
|
|
Packit Service |
c5cf8c |
inbuf[i] = (double) i;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
position = 0;
|
|
Packit Service |
c5cf8c |
/* Warm up the code and data */
|
|
Packit Service |
c5cf8c |
MPI_Pack(inbuf, 1, itype1, outbuf, packsize, &position, MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
tpack = 1e12;
|
|
Packit Service |
c5cf8c |
for (ntry = 0; ntry < 5; ntry++) {
|
|
Packit Service |
c5cf8c |
position = 0;
|
|
Packit Service |
c5cf8c |
t0 = MPI_Wtime();
|
|
Packit Service |
c5cf8c |
MPI_Pack(inbuf, 1, itype1, outbuf, packsize, &position, MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
t1 = MPI_Wtime() - t0;
|
|
Packit Service |
c5cf8c |
if (t1 < tpack)
|
|
Packit Service |
c5cf8c |
tpack = t1;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int one = 1;
|
|
Packit Service |
c5cf8c |
MPI_Aint displ = (MPI_Aint) inbuf;
|
|
Packit Service |
c5cf8c |
MPI_Type_create_struct(1, &one, &displ, &itype1, &stype1);
|
|
Packit Service |
c5cf8c |
MPI_Type_commit(&stype1);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
position = 0;
|
|
Packit Service |
c5cf8c |
/* Warm up the code and data */
|
|
Packit Service |
c5cf8c |
MPI_Pack(MPI_BOTTOM, 1, stype1, outbuf, packsize, &position, MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
tspack = 1e12;
|
|
Packit Service |
c5cf8c |
for (ntry = 0; ntry < 5; ntry++) {
|
|
Packit Service |
c5cf8c |
position = 0;
|
|
Packit Service |
c5cf8c |
t0 = MPI_Wtime();
|
|
Packit Service |
c5cf8c |
MPI_Pack(MPI_BOTTOM, 1, stype1, outbuf, packsize, &position, MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
t1 = MPI_Wtime() - t0;
|
|
Packit Service |
c5cf8c |
if (t1 < tspack)
|
|
Packit Service |
c5cf8c |
tspack = t1;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* Simple manual pack (without explicitly unrolling the index block)
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
tmanual = 1e12;
|
|
Packit Service |
c5cf8c |
for (ntry = 0; ntry < 5; ntry++) {
|
|
Packit Service |
c5cf8c |
const double *ppe = (const double *) inbuf;
|
|
Packit Service |
c5cf8c |
const int *id = (const int *) index_displacement;
|
|
Packit Service |
c5cf8c |
int k, j;
|
|
Packit Service |
c5cf8c |
t0 = MPI_Wtime();
|
|
Packit Service |
c5cf8c |
position = 0;
|
|
Packit Service |
c5cf8c |
for (i = 0; i < icount; i++) {
|
|
Packit Service |
c5cf8c |
outbuf2[position++] = ppe[id[i]];
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
t1 = MPI_Wtime() - t0;
|
|
Packit Service |
c5cf8c |
if (t1 < tmanual)
|
|
Packit Service |
c5cf8c |
tmanual = t1;
|
|
Packit Service |
c5cf8c |
/* Check on correctness */
|
|
Packit Service |
c5cf8c |
#ifdef PACK_IS_NATIVE
|
|
Packit Service |
c5cf8c |
if (memcmp(outbuf, outbuf2, position) != 0) {
|
|
Packit Service |
c5cf8c |
printf("Panic - pack buffers differ\n");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (verbose) {
|
|
Packit Service |
c5cf8c |
printf("Bytes packed = %d\n", position);
|
|
Packit Service |
c5cf8c |
printf("MPI_Pack time = %e, manual pack time = %e\n", tpack, tmanual);
|
|
Packit Service |
c5cf8c |
printf("Pack with struct = %e\n", tspack);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* The threshold here permits the MPI datatype to perform at up to
|
|
Packit Service |
c5cf8c |
* only one half the performance of simple user code. Note that the
|
|
Packit Service |
c5cf8c |
* example code above may be made faster through careful use of const,
|
|
Packit Service |
c5cf8c |
* restrict, and unrolling if the compiler doesn't already do that. */
|
|
Packit Service |
c5cf8c |
if (2 * tmanual < tpack) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
printf("MPI_Pack (block index) time = %e, manual pack time = %e\n", tpack, tmanual);
|
|
Packit Service |
c5cf8c |
printf("MPI_Pack time should be less than 2 times the manual time\n");
|
|
Packit Service |
c5cf8c |
printf("For most informative results, be sure to compile this test with optimization\n");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (2 * tmanual < tspack) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
printf("MPI_Pack (struct of block index)) time = %e, manual pack time = %e\n", tspack,
|
|
Packit Service |
c5cf8c |
tmanual);
|
|
Packit Service |
c5cf8c |
printf("MPI_Pack time should be less than 2 times the manual time\n");
|
|
Packit Service |
c5cf8c |
printf("For most informative results, be sure to compile this test with optimization\n");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Type_free(&itype1);
|
|
Packit Service |
c5cf8c |
MPI_Type_free(&stype1);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
free(inbuf);
|
|
Packit Service |
c5cf8c |
free(outbuf);
|
|
Packit Service |
c5cf8c |
free(outbuf2);
|
|
Packit Service |
c5cf8c |
free(index_displacement);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MTest_Finalize(errs);
|
|
Packit Service |
c5cf8c |
return MTestReturnValue(errs);
|
|
Packit Service |
c5cf8c |
}
|