[MPICH2-dev] Truncated messages

duncan.thomas at quadrics.com duncan.thomas at quadrics.com
Fri Jan 27 08:59:44 CST 2006


Hi

I've got some code that behaves differently between mpich 1 & 2 when handling truncated messages. Specifically it runs fine on mpich1, but errors out on mpich2.1.3. I was wondering if anybody could tell me if the code is valid, and if this change in behaviour is intentional?

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
    
#include <mpi.h>

#define BUFSIZE 128
    
#define FAIL_ERROR       123
#define RESFAIL_ERROR    123
#define INTERNAL_ERROR   123

void
if_error(char *function, char *data, int ret)
{
    if (ret == 0)
        return;

    if (data)
        printf("%s for %s returned %d (%#x)\n", function, data, ret, ret);
    else
        printf("%s returned %d (%#x)\n", function, ret, ret);

    exit(INTERNAL_ERROR);
}

int 
main (int argc, char *argv[])
{
    int ret;
    char *src, *sendrec;
    int bufsize = BUFSIZE;

    int myrank, nprocs;
    int i;
    MPI_Status status;

    int small_non_contig_struct_count = 3;
    int small_non_contig_struct_blocklens[] = {1, 1, 1};
    MPI_Aint small_non_contig_struct_disps[] = {0, 2, 4};
    MPI_Datatype small_non_contig_struct_types[] = {MPI_CHAR, MPI_CHAR, MPI_CHAR};
    MPI_Datatype small_non_contig_struct_type;

    int contig_indexed_count = 3;
    int contig_indexed_blocklens[] = {1, 2, 1};
    int contig_indexed_indices[] = {4, 8, 16};
    int contig_indexed_inner_type = MPI_INT;
    int contig_indexed_type;
    
    ret = MPI_Init(&argc, &argv);
    ret = MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
    ret = MPI_Comm_size(MPI_COMM_WORLD, &nprocs);

    if (nprocs < 2) {
        printf("Need at least 2 procs\n");
        exit(RESFAIL_ERROR);
    }

    ret = MPI_Type_struct(small_non_contig_struct_count, small_non_contig_struct_blocklens, small_non_contig_struct_disps, small_non_contig_struct_types, &small_non_contig_struct_type);
    if_error("MPI_Type_struct", "small_non_contig_struct_type", ret);
    
    ret = MPI_Type_commit(&small_non_contig_struct_type);
    if_error("MPI_Type_commit", "small_non_contig_struct_type", ret);

    ret = MPI_Type_indexed(contig_indexed_count, contig_indexed_blocklens, contig_indexed_indices, contig_indexed_inner_type, &contig_indexed_type);
    if_error("MPI_Type_indexed", "contig_indexed_type", ret);

    ret = MPI_Type_commit(&contig_indexed_type);
    if_error("MPI_Type_commit", "contig_indexed_type", ret);


    ret = MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &src);

    if (ret != 0) {
        printf("MPI_Alloc_mem src = #%x\n", ret);
        exit(INTERNAL_ERROR);
    }

    ret = MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &sendrec);

    if (ret != 0) {
        printf("MPI_Alloc_mem sendrec buf = #%x\n", ret);
        exit(INTERNAL_ERROR);
    }


    for (i=0; i<bufsize; i++) {
        src[i] = (char) i+1;
    }

    memset(sendrec, 0, bufsize);

    MPI_Barrier(MPI_COMM_WORLD);
    if (myrank == 1) {
        MPI_Send(src, 1, small_non_contig_struct_type, 0, 0xabc, MPI_COMM_WORLD);
    } else {
        MPI_Recv(sendrec, 1, contig_indexed_type, 1, 0xabc, MPI_COMM_WORLD, &status);
    }

    MPI_Barrier(MPI_COMM_WORLD);

    MPI_Free_mem(src);
    MPI_Free_mem(sendrec);

    return 0;
}


Under mpich1 it completes silently, under mpich2 I get an error stack.

Thanks

-- 
Duncan Thomas
Quadrics, One Bridewell Street, Bristol, BS1 2AA, UK
Telephone: +44 117 9155525  Fax: +44 117 9075395
Email: duncan.thomas at quadrics.com http://www.quadrics.com 




More information about the mpich2-dev mailing list