Skip to content

error with MPI_Unpack_external ("external32",...) and derived datatype #7851

Closed
@ggouaillardet

Description

@ggouaillardet

This is a followup of #5643

The reproducer below can be used to evidence this issue.

The issue occurs on master and the v4 release branches.
It does not occur on the v3 branches nor the 4.0.0 release.

fwiw, git bisect (on the v4.0.x branch )points to 4f754d0

@bosilca can you please have a look at it?

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

#include "mpi.h"

static void create_stattype(int chars, MPI_Datatype* dt_stat)
{
    int size = chars + sizeof(uint64_t);

    MPI_Datatype dt_filepath;
    MPI_Type_contiguous(chars, MPI_CHAR, &dt_filepath);

    MPI_Datatype types[2];
    types[0] = dt_filepath;  /* file name */
    types[1] = MPI_UINT64_T; /* file type */

    int blocklens[2] = {1, 1};
    MPI_Aint displs[2];
    displs[0] = 0;
    displs[1] = chars;

    MPI_Datatype dttemp;
    MPI_Type_create_struct(2, blocklens, displs, types, &dttemp);
    MPI_Type_create_resized(dttemp, 0, size, dt_stat);
    MPI_Type_commit(dt_stat);
    MPI_Type_free(&dttemp);

    MPI_Type_free(&dt_filepath);
    return;
}

int main(int argc, char *argv[]) {
    MPI_Init(&argc, &argv);
    char inbuf[120];
    char outbuf[120];

    uint64_t values[5] = {1, 2, 3, 4, 5};
    char* strings[5] = {"hello", "there", "world", "catss", "dogss"};

    /* to make things interesting, create a derived type that is a (string, UINT64_T) pair */

    MPI_Datatype dt;
    create_stattype(6, &dt);

    char* ptr = inbuf;
  
    int i;

    for (i=0; i<120; i++) {
       outbuf[i] = 'A';
    }

    for (i = 0; i < 5; i++) {
      strcpy(ptr, strings[i]);
      ptr += 6;
      *((uint64_t*)ptr) = values[i];
      ptr += sizeof(uint64_t);
    }

    MPI_Aint position=0;
    MPI_Unpack_external ("external32", inbuf, 70, &position, outbuf, 5, dt);
    for (i=70; i<120; i++) {
        if ('A' != outbuf[i]) {
            fprintf(stderr, "outbuf was overwritten at index %d\n", i);
            MPI_Abort(MPI_COMM_WORLD, 1);
        }
    }

    MPI_Finalize();
    return 0;
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions