Hello,

It seems for me that the endianness is wrong in Open MPI's I/O for the 
external32 data representation. :O

Find attached my test programs which write the integer -30 and the double 16.25 
into a file.
Here the output on my Linux system:

mpicc     c-xdr.c   -o c-xdr
mpicc     mpi-io-external32.c   -o mpi-io-external32
./c-xdr
Output file: c-xdr.dat
hexdump c-xdr.dat
0000000 ffff e2ff 3040 0040 0000 0000          
000000c
./mpi-io-external32
Output file: mpi-io-external32.dat
hexdump mpi-io-external32.dat
0000000 ffe2 ffff 0000 0000 4000 4030          
000000c


Best regards
Christoph Niethammer

--

Christoph Niethammer
High Performance Computing Center Stuttgart (HLRS)
Nobelstrasse 19
70569 Stuttgart

Tel: ++49(0)711-685-87203
email: nietham...@hlrs.de
http://www.hlrs.de/people/niethammer
#include <stdio.h>
#include <rpc/xdr.h>

int main(int argc, char* argv[]) {
    FILE *fp;
    XDR xdr_output;
    char filename[] = "c-xdr.dat";
    printf("Output file: %s\n", filename);
    int i = -30;
    double d = 16.25;

    fp = fopen(filename, "w+");
    xdrstdio_create(&xdr_output, fp, XDR_ENCODE);
    xdr_int(&xdr_output, &i);
    xdr_double(&xdr_output, &d);
    return 0;
}
#include <stdio.h>
#include <mpi.h>




int main(int argc, char* argv[]) {

    MPI_Comm comm;
    int comm_rank = 0;
    int comm_size = 1;
    MPI_File fh;
    MPI_Status status;
    MPI_Offset disp;
    MPI_Datatype etype;
    MPI_Datatype filetype;
    char datarep[] = "external32";

    int rc;
    int i;
    char filename[] = "mpi-io-external32.dat";
    printf("Output file: %s\n", filename);
    int N = -30;
    double d = 16.25;

    MPI_Init(&argc, &argv);
    comm = MPI_COMM_WORLD;
    MPI_Comm_rank(comm, &comm_rank);
    MPI_Comm_size(comm, &comm_size);
    //printf("Hello %d/%d\n", comm_rank, comm_size);

    rc = MPI_File_open(comm, filename, MPI_MODE_CREATE | MPI_MODE_RDWR, MPI_INFO_NULL, &fh);
    if(rc != MPI_SUCCESS) {
        printf("Error %d when opening file %s\n", rc, filename);
    }
    rc = MPI_File_set_view(fh, 0, MPI_INT, MPI_INT, datarep, MPI_INFO_NULL);
    if(rc != MPI_SUCCESS) {
        printf("Error %d when setting file view\n", rc);
    }
    if(comm_rank == 0) {
        //printf("Rank %d writing data...\n", comm_rank);
        MPI_File_write_shared(fh, &N, 1, MPI_INT, &status);
        MPI_File_write_shared(fh, &d, 1, MPI_DOUBLE, &status);
    }
    MPI_Barrier(comm);


    MPI_File_close(&fh);
    MPI_Finalize();
    return 0;
}

Reply via email to