Пример #1
0
int main( int argc, char *argv[] )
{
    int errs = 0;
    int size, rank, i, *buf, rc;
    MPI_File fh;
    MPI_Comm comm;
    MPI_Status status;

    MTest_Init( &argc, &argv );

    comm = MPI_COMM_WORLD;
    MPI_File_open( comm, (char*)"test.ord", 
		   MPI_MODE_RDWR | MPI_MODE_CREATE |
		   MPI_MODE_DELETE_ON_CLOSE, MPI_INFO_NULL, &fh );

    MPI_Comm_size( comm, &size );
    MPI_Comm_rank( comm, &rank );
    buf = (int *)malloc( size * sizeof(int) );
    buf[0] = rank;
    rc = MPI_File_write_ordered( fh, buf, 1, MPI_INT, &status );
    if (rc) {
	MTestPrintErrorMsg( "File_write_ordered", rc );
	errs++;
    }
    /* make sure all writes finish before we seek/read */
    MPI_Barrier(comm);
    
    /* Set the individual pointer to 0, since we want to use a read_all */
    MPI_File_seek( fh, 0, MPI_SEEK_SET ); 
    MPI_File_read_all( fh, buf, size, MPI_INT, &status );

    for (i=0; i<size; i++) {
	if (buf[i] != i) {
	    errs++;
	    fprintf( stderr, "%d: buf[%d] = %d\n", rank, i, buf[i] );
	}
    }

    MPI_File_seek_shared( fh, 0, MPI_SEEK_SET );
    for (i=0; i<size; i++) buf[i] = -1;
    MPI_File_read_ordered( fh, buf, 1, MPI_INT, &status );
    if (buf[0] != rank) {
	errs++;
	fprintf( stderr, "%d: buf[0] = %d\n", rank, buf[0] );
    }

    free( buf );
    MPI_File_close( &fh );

    MTest_Finalize( errs );
    MPI_Finalize();
    return 0;
}
Пример #2
0
int main(int argc, char **argv)
{
    int comm_size, comm_rank, i, by_rank, errs = 0;
    int rc;
    char *rma_win_addr, *local_buf;
    char check;
    MPI_Win win;
    MPI_Status status;

    MTest_Init(&argc, &argv);
    MPI_Comm_size(MPI_COMM_WORLD, &comm_size);
    MPI_Comm_rank(MPI_COMM_WORLD, &comm_rank);

    if ((comm_size > (MAX_BUF_SIZE / PUT_SIZE)) || (comm_size <= 2))
        MPI_Abort(MPI_COMM_WORLD, 1);

    /* If alloc mem returns an error (because too much memory is requested */
    MPI_Errhandler_set( MPI_COMM_WORLD, MPI_ERRORS_RETURN );

    rc = MPI_Alloc_mem(MAX_BUF_SIZE, MPI_INFO_NULL, (void *) &rma_win_addr);
    if (rc) {
	MTestPrintErrorMsg( "Unable to MPI_Alloc_mem space (not an error)", rc );
	MPI_Abort( MPI_COMM_WORLD, 0 );
    }

    memset(rma_win_addr, 0, MAX_BUF_SIZE);
    MPI_Win_create((void *) rma_win_addr, MAX_BUF_SIZE, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &win);

    rc = MPI_Alloc_mem(PUT_SIZE, MPI_INFO_NULL, (void *) &local_buf);
    if (rc) {
	MTestPrintErrorMsg( "Unable to MPI_Alloc_mem space (not an error)", rc );
	MPI_Abort( MPI_COMM_WORLD, 0 );
    }

    for (i = 0; i < PUT_SIZE; i++)
        local_buf[i] = 1;

    MPI_Barrier(MPI_COMM_WORLD);

    if (comm_rank == 0) { /* target */
        for (i = 0; i < (NUM_TIMES * (comm_size - 2)); i++) {
            /* Wait for a message from the server to notify me that
             * someone put some data in my window */
            MPI_Recv(&by_rank, 1, MPI_INT, 1, 0, MPI_COMM_WORLD, &status);

            /* Got a message from the server that 'by_rank' put some
             * data in my local window. Check the last byte to make
             * sure we got it correctly. */
            MPI_Win_lock(MPI_LOCK_SHARED, 0, 0, win);
            MPI_Get((void *) &check, 1, MPI_CHAR, 0, ((by_rank + 1) * PUT_SIZE) - 1, 1,
                    MPI_CHAR, win);
            MPI_Win_unlock(0, win);

            /* If this is not the value I expect, count it as an error */
            if (check != 1)
                errs++;

            /* Reset the buffer to zero for the next round */
            memset((void *) (rma_win_addr + (by_rank * PUT_SIZE)), 0, PUT_SIZE);

            /* Tell the origin that I am ready for the next round */
            MPI_Send(NULL, 0, MPI_INT, by_rank, 0, MPI_COMM_WORLD);
        }
    }

    else if (comm_rank == 1) { /* server */
        for (i = 0; i < (NUM_TIMES * (comm_size - 2)); i++) {
            /* Wait for a message from any of the origin processes
             * informing me that it has put data to the target
             * process */
            MPI_Recv(NULL, 0, MPI_INT, MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &status);
            by_rank = status.MPI_SOURCE;

            /* Tell the target process that it should be seeing some
             * data in its local buffer */
            MPI_Send(&by_rank, 1, MPI_INT, 0, 0, MPI_COMM_WORLD);
        }
    }

    else { /* origin */
        for (i = 0; i < NUM_TIMES; i++) {
            /* Put some data in the target window */
            MPI_Win_lock(MPI_LOCK_SHARED, 0, 0, win);
            MPI_Put(local_buf, PUT_SIZE, MPI_CHAR, 0, comm_rank * PUT_SIZE, PUT_SIZE,
                    MPI_CHAR, win);
            MPI_Win_unlock(0, win);

            /* Tell the server that the put has completed */
            MPI_Send(NULL, 0, MPI_INT, 1, 0, MPI_COMM_WORLD);

            /* Wait for a message from the target that it is ready for
             * the next round */
            MPI_Recv(NULL, 0, MPI_INT, 0, 0, MPI_COMM_WORLD, &status);
        }
    }

    MPI_Win_free(&win);

    MPI_Free_mem(rma_win_addr);
    MPI_Free_mem(local_buf);

    MTest_Finalize(errs);
    MPI_Finalize();

    return 0;
}
Пример #3
0
/*
 * This test looks at the handling of logical and for types that are not
 * integers or are not required integers (e.g., long long).  MPICH allows
 * these as well.  A strict MPI test should not include this test.
 */
int main(int argc, char *argv[])
{
    int errs = 0;
    int rc;
    int rank, size;
    MPI_Comm comm;
    char cinbuf[3], coutbuf[3];
    signed char scinbuf[3], scoutbuf[3];
    unsigned char ucinbuf[3], ucoutbuf[3];
    float finbuf[3], foutbuf[3];
    double dinbuf[3], doutbuf[3];

    MTest_Init(&argc, &argv);

    comm = MPI_COMM_WORLD;
    /* Set errors return so that we can provide better information
     * should a routine reject one of the operand/datatype pairs */
    MPI_Errhandler_set(comm, MPI_ERRORS_RETURN);

    MPI_Comm_rank(comm, &rank);
    MPI_Comm_size(comm, &size);

#ifndef USE_STRICT_MPI
    /* char */
    MTestPrintfMsg(10, "Reduce of MPI_CHAR\n");
    cinbuf[0] = 1;
    cinbuf[1] = 0;
    cinbuf[2] = (rank > 0);

    coutbuf[0] = 0;
    coutbuf[1] = 1;
    coutbuf[2] = 1;
    rc = MPI_Reduce(cinbuf, coutbuf, 3, MPI_CHAR, MPI_LXOR, 0, comm);
    if (rc) {
        MTestPrintErrorMsg("MPI_LXOR and MPI_CHAR", rc);
        errs++;
    } else {
        if (rank == 0) {
            if (coutbuf[0] != (size % 2)) {
                errs++;
                fprintf(stderr, "char XOR(1) test failed\n");
            }
            if (coutbuf[1]) {
                errs++;
                fprintf(stderr, "char XOR(0) test failed\n");
            }
            if (coutbuf[2] == (size % 2) && size > 1) {
                errs++;
                fprintf(stderr, "char XOR(>) test failed\n");
            }
        }
    }
#endif /* USE_STRICT_MPI */

    /* signed char */
    MTestPrintfMsg(10, "Reduce of MPI_SIGNED_CHAR\n");
    scinbuf[0] = 1;
    scinbuf[1] = 0;
    scinbuf[2] = (rank > 0);

    scoutbuf[0] = 0;
    scoutbuf[1] = 1;
    scoutbuf[2] = 1;
    rc = MPI_Reduce(scinbuf, scoutbuf, 3, MPI_SIGNED_CHAR, MPI_LXOR, 0, comm);
    if (rc) {
        MTestPrintErrorMsg("MPI_LXOR and MPI_SIGNED_CHAR", rc);
        errs++;
    } else {
        if (rank == 0) {
            if (scoutbuf[0] != (size % 2)) {
                errs++;
                fprintf(stderr, "signed char XOR(1) test failed\n");
            }
            if (scoutbuf[1]) {
                errs++;
                fprintf(stderr, "signed char XOR(0) test failed\n");
            }
            if (scoutbuf[2] == (size % 2) && size > 1) {
                errs++;
                fprintf(stderr, "signed char XOR(>) test failed\n");
            }
        }
    }

    /* unsigned char */
    MTestPrintfMsg(10, "Reduce of MPI_UNSIGNED_CHAR\n");
    ucinbuf[0] = 1;
    ucinbuf[1] = 0;
    ucinbuf[2] = (rank > 0);

    ucoutbuf[0] = 0;
    ucoutbuf[1] = 1;
    ucoutbuf[2] = 1;
    rc = MPI_Reduce(ucinbuf, ucoutbuf, 3, MPI_UNSIGNED_CHAR, MPI_LXOR, 0, comm);
    if (rc) {
        MTestPrintErrorMsg("MPI_LXOR and MPI_UNSIGNED_CHAR", rc);
        errs++;
    } else {
        if (rank == 0) {
            if (ucoutbuf[0] != (size % 2)) {
                errs++;
                fprintf(stderr, "unsigned char XOR(1) test failed\n");
            }
            if (ucoutbuf[1]) {
                errs++;
                fprintf(stderr, "unsigned char XOR(0) test failed\n");
            }
            if (ucoutbuf[2] == (size % 2) && size > 1) {
                errs++;
                fprintf(stderr, "unsigned char XOR(>) test failed\n");
            }
        }
    }

#ifndef USE_STRICT_MPI
    /* float */
    MTestPrintfMsg(10, "Reduce of MPI_FLOAT\n");
    finbuf[0] = 1;
    finbuf[1] = 0;
    finbuf[2] = (rank > 0);

    foutbuf[0] = 0;
    foutbuf[1] = 1;
    foutbuf[2] = 1;
    rc = MPI_Reduce(finbuf, foutbuf, 3, MPI_FLOAT, MPI_LXOR, 0, comm);
    if (rc) {
        MTestPrintErrorMsg("MPI_LXOR and MPI_FLOAT", rc);
        errs++;
    } else {
        if (rank == 0) {
            if (foutbuf[0] != (size % 2)) {
                errs++;
                fprintf(stderr, "float XOR(1) test failed\n");
            }
            if (foutbuf[1]) {
                errs++;
                fprintf(stderr, "float XOR(0) test failed\n");
            }
            if (foutbuf[2] == (size % 2) && size > 1) {
                errs++;
                fprintf(stderr, "float XOR(>) test failed\n");
            }
        }
    }

    /* double */
    MTestPrintfMsg(10, "Reduce of MPI_DOUBLE\n");
    dinbuf[0] = 1;
    dinbuf[1] = 0;
    dinbuf[2] = (rank > 0);

    doutbuf[0] = 0;
    doutbuf[1] = 1;
    doutbuf[2] = 1;
    rc = MPI_Reduce(dinbuf, doutbuf, 3, MPI_DOUBLE, MPI_LXOR, 0, comm);
    if (rc) {
        MTestPrintErrorMsg("MPI_LXOR and MPI_DOUBLE", rc);
        errs++;
    } else {
        if (rank == 0) {
            if (doutbuf[0] != (size % 2)) {
                errs++;
                fprintf(stderr, "double XOR(1) test failed\n");
            }
            if (doutbuf[1]) {
                errs++;
                fprintf(stderr, "double XOR(0) test failed\n");
            }
            if (doutbuf[2] == (size % 2) && size > 1) {
                errs++;
                fprintf(stderr, "double XOR(>) test failed\n");
            }
        }
    }

#ifdef HAVE_LONG_DOUBLE
    {
        long double ldinbuf[3], ldoutbuf[3];
        /* long double */
        MTEST_VG_MEM_INIT(ldinbuf, 3 * sizeof(ldinbuf[0]));
        ldinbuf[0] = 1;
        ldinbuf[1] = 0;
        ldinbuf[2] = (rank > 0);

        ldoutbuf[0] = 0;
        ldoutbuf[1] = 1;
        ldoutbuf[2] = 1;
        if (MPI_LONG_DOUBLE != MPI_DATATYPE_NULL) {
            MTestPrintfMsg(10, "Reduce of MPI_LONG_DOUBLE\n");
            rc = MPI_Reduce(ldinbuf, ldoutbuf, 3, MPI_LONG_DOUBLE, MPI_LXOR, 0, comm);
            if (rc) {
                MTestPrintErrorMsg("MPI_LXOR and MPI_LONG_DOUBLE", rc);
                errs++;
            } else {
                if (rank == 0) {
                    if (ldoutbuf[0] != (size % 2)) {
                        errs++;
                        fprintf(stderr, "long double XOR(1) test failed\n");
                    }
                    if (ldoutbuf[1]) {
                        errs++;
                        fprintf(stderr, "long double XOR(0) test failed\n");
                    }
                    if (ldoutbuf[2] == (size % 2) && size > 1) {
                        errs++;
                        fprintf(stderr, "long double XOR(>) test failed\n");
                    }
                }
            }
        }
    }
#endif /* HAVE_LONG_DOUBLE */
#endif /* USE_STRICT_MPI */

#ifdef HAVE_LONG_LONG
    {
        long long llinbuf[3], lloutbuf[3];
        /* long long */
        llinbuf[0] = 1;
        llinbuf[1] = 0;
        llinbuf[2] = (rank > 0);

        lloutbuf[0] = 0;
        lloutbuf[1] = 1;
        lloutbuf[2] = 1;
        if (MPI_LONG_LONG != MPI_DATATYPE_NULL) {
            MTestPrintfMsg(10, "Reduce of MPI_LONG_LONG\n");
            rc = MPI_Reduce(llinbuf, lloutbuf, 3, MPI_LONG_LONG, MPI_LXOR, 0, comm);
            if (rc) {
                MTestPrintErrorMsg("MPI_LXOR and MPI_LONG_LONG", rc);
                errs++;
            } else {
                if (rank == 0) {
                    if (lloutbuf[0] != (size % 2)) {
                        errs++;
                        fprintf(stderr, "long long XOR(1) test failed\n");
                    }
                    if (lloutbuf[1]) {
                        errs++;
                        fprintf(stderr, "long long XOR(0) test failed\n");
                    }
                    if (lloutbuf[2] == (size % 2) && size > 1) {
                        errs++;
                        fprintf(stderr, "long long XOR(>) test failed\n");
                    }
                }
            }
        }
    }
#endif

    MPI_Errhandler_set(comm, MPI_ERRORS_ARE_FATAL);
    MTest_Finalize(errs);
    return MTestReturnValue(errs);
}
Пример #4
0
/*
 * This test looks at the handling of logical and for types that are not
 * integers or are not required integers (e.g., long long).  MPICH allows
 * these as well.  A strict MPI test should not include this test.
 */
int main(int argc, char *argv[])
{
    int errs = 0, err;
    int rank, size;
    MPI_Comm comm;
    char cinbuf[3], coutbuf[3];
    signed char scinbuf[3], scoutbuf[3];
    unsigned char ucinbuf[3], ucoutbuf[3];
    float finbuf[3], foutbuf[3];
    double dinbuf[3], doutbuf[3];

    MTest_Init(&argc, &argv);

    comm = MPI_COMM_WORLD;

    MPI_Comm_rank(comm, &rank);
    MPI_Comm_size(comm, &size);

    /* Some MPI implementations do not implement all of the required
     * (datatype,operations) combinations, and further, they do not
     * always provide clear and specific error messages.  By catching
     * the error, we can provide a higher quality, more specific message.
     */
    MPI_Comm_set_errhandler(comm, MPI_ERRORS_RETURN);

#ifndef USE_STRICT_MPI
    /* char */
    MTestPrintfMsg(10, "Reduce of MPI_CHAR\n");
    cinbuf[0] = 1;
    cinbuf[1] = 0;
    cinbuf[2] = (rank > 0);

    coutbuf[0] = 0;
    coutbuf[1] = 1;
    coutbuf[2] = 1;
    err = MPI_Reduce(cinbuf, coutbuf, 3, MPI_CHAR, MPI_LOR, 0, comm);
    if (err) {
        errs++;
        MTestPrintErrorMsg("MPI_LOR and MPI_CHAR", err);
    }
    else {
        if (rank == 0) {
            if (!coutbuf[0]) {
                errs++;
                fprintf(stderr, "char OR(1) test failed\n");
            }
            if (coutbuf[1]) {
                errs++;
                fprintf(stderr, "char OR(0) test failed\n");
            }
            if (!coutbuf[2] && size > 1) {
                errs++;
                fprintf(stderr, "char OR(>) test failed\n");
            }
        }
    }
#endif /* USE_STRICT_MPI */

    /* signed char */
    MTestPrintfMsg(10, "Reduce of MPI_SIGNED_CHAR\n");
    scinbuf[0] = 1;
    scinbuf[1] = 0;
    scinbuf[2] = (rank > 0);

    scoutbuf[0] = 0;
    scoutbuf[1] = 1;
    scoutbuf[2] = 1;
    err = MPI_Reduce(scinbuf, scoutbuf, 3, MPI_SIGNED_CHAR, MPI_LOR, 0, comm);
    if (err) {
        errs++;
        MTestPrintErrorMsg("MPI_LOR and MPI_SIGNED_CHAR", err);
    }
    else {
        if (rank == 0) {
            if (!scoutbuf[0]) {
                errs++;
                fprintf(stderr, "signed char OR(1) test failed\n");
            }
            if (scoutbuf[1]) {
                errs++;
                fprintf(stderr, "signed char OR(0) test failed\n");
            }
            if (!scoutbuf[2] && size > 1) {
                errs++;
                fprintf(stderr, "signed char OR(>) test failed\n");
            }
        }
    }

    /* unsigned char */
    MTestPrintfMsg(10, "Reduce of MPI_UNSIGNED_CHAR\n");
    ucinbuf[0] = 1;
    ucinbuf[1] = 0;
    ucinbuf[2] = (rank > 0);

    ucoutbuf[0] = 0;
    ucoutbuf[1] = 1;
    ucoutbuf[2] = 1;
    err = MPI_Reduce(ucinbuf, ucoutbuf, 3, MPI_UNSIGNED_CHAR, MPI_LOR, 0, comm);
    if (err) {
        errs++;
        MTestPrintErrorMsg("MPI_LOR and MPI_UNSIGNED_CHAR", err);
    }
    else {
        if (rank == 0) {
            if (!ucoutbuf[0]) {
                errs++;
                fprintf(stderr, "unsigned char OR(1) test failed\n");
            }
            if (ucoutbuf[1]) {
                errs++;
                fprintf(stderr, "unsigned char OR(0) test failed\n");
            }
            if (!ucoutbuf[2] && size > 1) {
                errs++;
                fprintf(stderr, "unsigned char OR(>) test failed\n");
            }
        }
    }

#ifndef USE_STRICT_MPI
    /* float */
    MTestPrintfMsg(10, "Reduce of MPI_FLOAT\n");
    finbuf[0] = 1;
    finbuf[1] = 0;
    finbuf[2] = (rank > 0);

    foutbuf[0] = 0;
    foutbuf[1] = 1;
    foutbuf[2] = 1;
    err = MPI_Reduce(finbuf, foutbuf, 3, MPI_FLOAT, MPI_LOR, 0, comm);
    if (err) {
        errs++;
        MTestPrintErrorMsg("MPI_LOR and MPI_FLOAT", err);
    }
    else {
        if (rank == 0) {
            if (!foutbuf[0]) {
                errs++;
                fprintf(stderr, "float OR(1) test failed\n");
            }
            if (foutbuf[1]) {
                errs++;
                fprintf(stderr, "float OR(0) test failed\n");
            }
            if (!foutbuf[2] && size > 1) {
                errs++;
                fprintf(stderr, "float OR(>) test failed\n");
            }
        }
    }

    /* double */
    MTestPrintfMsg(10, "Reduce of MPI_DOUBLE\n");
    dinbuf[0] = 1;
    dinbuf[1] = 0;
    dinbuf[2] = (rank > 0);

    doutbuf[0] = 0;
    doutbuf[1] = 1;
    doutbuf[2] = 1;
    err = MPI_Reduce(dinbuf, doutbuf, 3, MPI_DOUBLE, MPI_LOR, 0, comm);
    if (err) {
        errs++;
        MTestPrintErrorMsg("MPI_LOR and MPI_DOUBLE", err);
    }
    else {
        if (rank == 0) {
            if (!doutbuf[0]) {
                errs++;
                fprintf(stderr, "double OR(1) test failed\n");
            }
            if (doutbuf[1]) {
                errs++;
                fprintf(stderr, "double OR(0) test failed\n");
            }
            if (!doutbuf[2] && size > 1) {
                errs++;
                fprintf(stderr, "double OR(>) test failed\n");
            }
        }
    }

#ifdef HAVE_LONG_DOUBLE
    {
        long double ldinbuf[3], ldoutbuf[3];
        /* long double */
        MTEST_VG_MEM_INIT(ldinbuf, 3* sizeof(ldinbuf[0]));
        ldinbuf[0] = 1;
        ldinbuf[1] = 0;
        ldinbuf[2] = (rank > 0);

        ldoutbuf[0] = 0;
        ldoutbuf[1] = 1;
        ldoutbuf[2] = 1;
        if (MPI_LONG_DOUBLE != MPI_DATATYPE_NULL) {
            MTestPrintfMsg(10, "Reduce of MPI_LONG_DOUBLE\n");
            err = MPI_Reduce(ldinbuf, ldoutbuf, 3, MPI_LONG_DOUBLE, MPI_LOR, 0, comm);
            if (err) {
                errs++;
                MTestPrintErrorMsg("MPI_LOR and MPI_LONG_DOUBLE", err);
            }
            else {
                if (rank == 0) {
                    if (!ldoutbuf[0]) {
                        errs++;
                        fprintf(stderr, "long double OR(1) test failed\n");
                    }
                    if (ldoutbuf[1]) {
                        errs++;
                        fprintf(stderr, "long double OR(0) test failed\n");
                    }
                    if (!ldoutbuf[2] && size > 1) {
                        errs++;
                        fprintf(stderr, "long double OR(>) test failed\n");
                    }
                }
            }
        }
    }
#endif /* HAVE_LONG_DOUBLE */
#endif /* USE_STRICT_MPI */

#ifdef HAVE_LONG_LONG
    {
        long long llinbuf[3], lloutbuf[3];
        /* long long */
        llinbuf[0] = 1;
        llinbuf[1] = 0;
        llinbuf[2] = (rank > 0);

        lloutbuf[0] = 0;
        lloutbuf[1] = 1;
        lloutbuf[2] = 1;
        if (MPI_LONG_LONG != MPI_DATATYPE_NULL) {
            MTestPrintfMsg(10, "Reduce of MPI_LONG_LONG\n");
            err = MPI_Reduce(llinbuf, lloutbuf, 3, MPI_LONG_LONG, MPI_LOR, 0, comm);
            if (err) {
                errs++;
                MTestPrintErrorMsg("MPI_LOR and MPI_LONG_LONG", err);
            }
            else {
                if (rank == 0) {
                    if (!lloutbuf[0]) {
                        errs++;
                        fprintf(stderr, "long long OR(1) test failed\n");
                    }
                    if (lloutbuf[1]) {
                        errs++;
                        fprintf(stderr, "long long OR(0) test failed\n");
                    }
                    if (!lloutbuf[2] && size > 1) {
                        errs++;
                        fprintf(stderr, "long long OR(>) test failed\n");
                    }
                }
            }
        }
    }
#endif

    MPI_Errhandler_set(comm, MPI_ERRORS_ARE_FATAL);
    MTest_Finalize(errs);
    MPI_Finalize();
    return 0;
}
Пример #5
0
int main(int argc, char *argv[])
{
    MPI_File fh;
    char emsg[MPI_MAX_ERROR_STRING];
    int emsglen, err, ec, errs = 0;
    int amode, rank;
    char *name = 0;
    MPI_Status st;
    int outbuf[BUFLEN], inbuf[BUFLEN];

    MTest_Init(&argc, &argv);

    name = "not-a-file-to-use";
    /* Try to open a file that does/should not exist */
    /* Note that no error message should be printed by MPI_File_open,
     * even when there is an error */
    err = MPI_File_open(MPI_COMM_WORLD, name, MPI_MODE_RDONLY, MPI_INFO_NULL, &fh);
    if (err == MPI_SUCCESS) {
        errs++;
        printf("Did not return error when opening a file that does not exist\n");
        MPI_File_close(&fh);
        MPI_File_delete(name, MPI_INFO_NULL);
    } else {
        MPI_Error_class(err, &ec);
        MPI_Error_string(err, emsg, &emsglen);
        MTestPrintfMsg(2, "Error msg from open: %s\n", emsg);
        if (ec != MPI_ERR_NO_SUCH_FILE && ec != MPI_ERR_IO) {
            errs++;
            printf("Did not return class ERR_NO_SUCH_FILE or ERR_IO\n");
            printf("Returned class %d, message %s\n", ec, emsg);
        }
    }

    /* Now, create a file, write data into it; close, then reopen as
     * read only and try to write to it */

    amode = MPI_MODE_CREATE | MPI_MODE_WRONLY;
    name = "mpio-test-openerrs";

    err = MPI_File_open(MPI_COMM_WORLD, name, amode, MPI_INFO_NULL, &fh);
    if (err) {
        errs++;
        MTestPrintErrorMsg("Unable to open file for writing", err);
    } else {
        MPI_Comm_rank(MPI_COMM_WORLD, &rank);
        memset(outbuf, 'A' + rank, BUFLEN);

        err = MPI_File_write_at(fh, rank * BUFLEN, outbuf, BUFLEN, MPI_BYTE, &st);
        if (err) {
            errs++;
            MTestPrintErrorMsg("Unable to write file", err);
        }
        MPI_File_close(&fh);
    }

    /* Now, open for read only, and delete on close */
    amode = MPI_MODE_RDONLY | MPI_MODE_DELETE_ON_CLOSE;

    err = MPI_File_open(MPI_COMM_WORLD, name, amode, MPI_INFO_NULL, &fh);
    if (err) {
        errs++;
        MTestPrintErrorMsg("Unable to reopen file for reading", err);
    } else {
        /* Try to read it */

        /* Clear buffer before reading into it */

        memset(inbuf, 0, BUFLEN);

        err = MPI_File_read_at(fh, rank * BUFLEN, inbuf, BUFLEN, MPI_BYTE, &st);
        if (err) {
            errs++;
            MTestPrintErrorMsg("Unable to read file", err);
        }

        /* Try to write it (should fail) */
        err = MPI_File_write_at(fh, rank * BUFLEN, outbuf, BUFLEN, MPI_BYTE, &st);
        if (err == MPI_SUCCESS) {
            errs++;
            printf("Write operation succeeded to read-only file\n");
        } else {
            /* Look at error class */
            MPI_Error_class(err, &ec);
            if (ec != MPI_ERR_READ_ONLY && ec != MPI_ERR_ACCESS) {
                errs++;
                printf("Unexpected error class %d when writing to read-only file\n", ec);
                MTestPrintErrorMsg("Error msg is: ", err);
            }
        }
        err = MPI_File_close(&fh);
        if (err) {
            errs++;
            MTestPrintErrorMsg("Failed to close", err);
        }

        /* No MPI_Barrier is required here */

        /*
         *  Test open without CREATE to see if DELETE_ON_CLOSE worked.
         *  This should fail if file was deleted correctly.
         */

        amode = MPI_MODE_RDONLY;
        err = MPI_File_open(MPI_COMM_WORLD, name, amode, MPI_INFO_NULL, &fh);
        if (err == MPI_SUCCESS) {
            errs++;
            printf("File was not deleted!\n");
            MPI_File_close(&fh);
        } else {
            MPI_Error_class(err, &ec);
            if (ec != MPI_ERR_NO_SUCH_FILE && ec != MPI_ERR_IO) {
                errs++;
                printf("Did not return class ERR_NO_SUCH_FILE or ERR_IO\n");
                printf("Returned class %d, message %s\n", ec, emsg);
            }
        }
    }
    /* */

    /* Find out how many errors we saw */
    MTest_Finalize(errs);

    return MTestReturnValue(errs);
}
Пример #6
0
int main( int argc, char *argv[] )
{
    int errs = 0;
    int size, rank, i, *buf, count, rc;
    MPI_File fh;
    MPI_Comm comm;
    MPI_Status status;

    MTest_Init( &argc, &argv );

    comm = MPI_COMM_WORLD;
    rc = MPI_File_open( comm, (char*)"test.ord", 
			MPI_MODE_RDWR | MPI_MODE_CREATE |
			MPI_MODE_DELETE_ON_CLOSE, MPI_INFO_NULL, &fh );
    if (rc) {
	MTestPrintErrorMsg( "File_open", rc );
	errs++;
	/* If the open fails, there isn't anything else that we can do */
	goto fn_fail;
    }


    MPI_Comm_size( comm, &size );
    MPI_Comm_rank( comm, &rank );
    buf = (int *)malloc( size * sizeof(int) );
    buf[0] = rank;
    /* Write to file */
    rc = MPI_File_write_ordered( fh, buf, 1, MPI_INT, &status );
    if (rc) {
	MTestPrintErrorMsg( "File_write_ordered", rc );
	errs++;
    }
    else {
	MPI_Get_count( &status, MPI_INT, &count );
	if (count != 1) {
	    errs++;
	    fprintf( stderr, "Wrong count (%d) on write-ordered\n", count );
	}
    }

    /* Set the individual pointer to 0, since we want to use a read_all */
    MPI_File_seek( fh, 0, MPI_SEEK_SET ); 

    /* Read nothing (check status) */
    memset( &status, 0xff, sizeof(MPI_Status) );
    MPI_File_read( fh, buf, 0, MPI_INT, &status );
    MPI_Get_count( &status, MPI_INT, &count );
    if (count != 0) {
	errs++;
	fprintf( stderr, "Count not zero (%d) on read\n", count );
    }

    /* Write nothing (check status) */
    memset( &status, 0xff, sizeof(MPI_Status) );
    MPI_File_write( fh, buf, 0, MPI_INT, &status );
    if (count != 0) {
	errs++;
	fprintf( stderr, "Count not zero (%d) on write\n", count );
    }

    /* Read shared nothing (check status) */
    MPI_File_seek_shared( fh, 0, MPI_SEEK_SET );
    /* Read nothing (check status) */
    memset( &status, 0xff, sizeof(MPI_Status) );
    MPI_File_read_shared( fh, buf, 0, MPI_INT, &status );
    MPI_Get_count( &status, MPI_INT, &count );
    if (count != 0) {
	errs++;
	fprintf( stderr, "Count not zero (%d) on read shared\n", count );
    }
    
    /* Write nothing (check status) */
    memset( &status, 0xff, sizeof(MPI_Status) );
    MPI_File_write_shared( fh, buf, 0, MPI_INT, &status );
    if (count != 0) {
	errs++;
	fprintf( stderr, "Count not zero (%d) on write\n", count );
    }

    MPI_Barrier( comm );

    MPI_File_seek_shared( fh, 0, MPI_SEEK_SET );
    for (i=0; i<size; i++) buf[i] = -1;
    MPI_File_read_ordered( fh, buf, 1, MPI_INT, &status );
    if (buf[0] != rank) {
	errs++;
	fprintf( stderr, "%d: buf = %d\n", rank, buf[0] );
    }

    free( buf );

    MPI_File_close( &fh );

 fn_fail:
    MTest_Finalize( errs );
    MPI_Finalize();
    return 0;
}
Пример #7
0
/*
 * This test looks at the handling of logical and for types that are not 
 * integers or are not required integers (e.g., long long).  MPICH allows
 * these as well.  A strict MPI test should not include this test.
 */
int main( int argc, char *argv[] )
{
    int errs = 0;
    int rc;
    int rank, size;
    MPI_Comm      comm;
    char cinbuf[3], coutbuf[3];
    signed char scinbuf[3], scoutbuf[3];
    unsigned char ucinbuf[3], ucoutbuf[3];
    short sinbuf[3], soutbuf[3];
    unsigned short usinbuf[3], usoutbuf[3];
    long linbuf[3], loutbuf[3];
    unsigned long ulinbuf[3], uloutbuf[3];
    unsigned uinbuf[3], uoutbuf[3];
    int iinbuf[3], ioutbuf[3];
    

    MTest_Init( &argc, &argv );

    comm = MPI_COMM_WORLD;
    /* Set errors return so that we can provide better information 
       should a routine reject one of the operand/datatype pairs */
    MPI_Errhandler_set( comm, MPI_ERRORS_RETURN );

    MPI_Comm_rank( comm, &rank );
    MPI_Comm_size( comm, &size );

#ifndef USE_STRICT_MPI
    /* char */
    MTestPrintfMsg( 10, "Reduce of MPI_CHAR\n" );
    cinbuf[0] = 0xff;
    cinbuf[1] = 0;
    cinbuf[2] = (rank > 0) ? 0x3c : 0xc3;

    coutbuf[0] = 0xf;
    coutbuf[1] = 1;
    coutbuf[2] = 1;
    rc = MPI_Reduce( cinbuf, coutbuf, 3, MPI_CHAR, MPI_BXOR, 0, comm );
    if (rc) {
	MTestPrintErrorMsg( "MPI_BXOR and MPI_CHAR", rc );
	errs++;
    }
    else {
	if (rank == 0) {
	    if (coutbuf[0] != ((size % 2) ? (char)0xff : (char)0) ) {
		errs++;
		fprintf( stderr, "char BXOR(1) test failed\n" );
	    }
	    if (coutbuf[1]) {
		errs++;
		fprintf( stderr, "char BXOR(0) test failed\n" );
	    }
	    if (coutbuf[2] != ((size % 2) ? (char)0xc3 : (char)0xff)) {
		errs++;
		fprintf( stderr, "char BXOR(>) test failed\n" );
	    }
	}
    }
#endif /* USE_STRICT_MPI */

    /* signed char */
    MTestPrintfMsg( 10, "Reduce of MPI_SIGNED_CHAR\n" );
    scinbuf[0] = 0xff;
    scinbuf[1] = 0;
    scinbuf[2] = (rank > 0) ? 0x3c : 0xc3;

    scoutbuf[0] = 0xf;
    scoutbuf[1] = 1;
    scoutbuf[2] = 1;
    rc = MPI_Reduce( scinbuf, scoutbuf, 3, MPI_SIGNED_CHAR, MPI_BXOR, 0, comm );
    if (rc) {
	MTestPrintErrorMsg( "MPI_BXOR and MPI_SIGNED_CHAR", rc );
	errs++;
    }
    else {
	if (rank == 0) {
	    if (scoutbuf[0] != ((size % 2) ? (signed char)0xff : (signed char)0) ) {
		errs++;
		fprintf( stderr, "signed char BXOR(1) test failed\n" );
	    }
	    if (scoutbuf[1]) {
		errs++;
		fprintf( stderr, "signed char BXOR(0) test failed\n" );
	    }
	    if (scoutbuf[2] != ((size % 2) ? (signed char)0xc3 : (signed char)0xff)) {
		errs++;
		fprintf( stderr, "signed char BXOR(>) test failed\n" );
	    }
	}
    }

    /* unsigned char */
    MTestPrintfMsg( 10, "Reduce of MPI_UNSIGNED_CHAR\n" );
    ucinbuf[0] = 0xff;
    ucinbuf[1] = 0;
    ucinbuf[2] = (rank > 0) ? 0x3c : 0xc3;

    ucoutbuf[0] = 0;
    ucoutbuf[1] = 1;
    ucoutbuf[2] = 1;
    rc = MPI_Reduce( ucinbuf, ucoutbuf, 3, MPI_UNSIGNED_CHAR, MPI_BXOR, 0, comm );
    if (rc) {
	MTestPrintErrorMsg( "MPI_BXOR and MPI_UNSIGNED_CHAR", rc );
	errs++;
    }
    else {
	if (rank == 0) {
	    if (ucoutbuf[0] != ((size % 2) ? 0xff : 0)) {
		errs++;
		fprintf( stderr, "unsigned char BXOR(1) test failed\n" );
	    }
	    if (ucoutbuf[1]) {
		errs++;
		fprintf( stderr, "unsigned char BXOR(0) test failed\n" );
	    }
	    if (ucoutbuf[2] != ((size % 2) ? (unsigned char)0xc3 : (unsigned char)0xff)) {
		errs++;
		fprintf( stderr, "unsigned char BXOR(>) test failed\n" );
	    }
	}
    }

    /* bytes */
    MTestPrintfMsg( 10, "Reduce of MPI_BYTE\n" );
    cinbuf[0] = 0xff;
    cinbuf[1] = 0;
    cinbuf[2] = (rank > 0) ? 0x3c : 0xc3;

    coutbuf[0] = 0;
    coutbuf[1] = 1;
    coutbuf[2] = 1;
    rc = MPI_Reduce( cinbuf, coutbuf, 3, MPI_BYTE, MPI_BXOR, 0, comm );
    if (rc) {
	MTestPrintErrorMsg( "MPI_BXOR and MPI_BYTE", rc );
	errs++;
    }
    else {
	if (rank == 0) {
	    if (coutbuf[0] != ((size % 2) ? (char)0xff : 0)) {
		errs++;
		fprintf( stderr, "byte BXOR(1) test failed\n" );
	    }
	    if (coutbuf[1]) {
		errs++;
		fprintf( stderr, "byte BXOR(0) test failed\n" );
	    }
	    if (coutbuf[2] != ((size % 2) ? (char)0xc3 : (char)0xff)) {
		errs++;
		fprintf( stderr, "byte BXOR(>) test failed\n" );
	    }
	}
    }

    /* short */
    MTestPrintfMsg( 10, "Reduce of MPI_SHORT\n" );
    sinbuf[0] = 0xffff;
    sinbuf[1] = 0;
    sinbuf[2] = (rank > 0) ? 0x3c3c : 0xc3c3;

    soutbuf[0] = 0;
    soutbuf[1] = 1;
    soutbuf[2] = 1;
    rc = MPI_Reduce( sinbuf, soutbuf, 3, MPI_SHORT, MPI_BXOR, 0, comm );
    if (rc) {
	MTestPrintErrorMsg( "MPI_BXOR and MPI_SHORT", rc );
	errs++;
    }
    else {
	if (rank == 0) {
	    if (soutbuf[0] != ((size % 2) ? (short)0xffff : 0)) {
		errs++;
		fprintf( stderr, "short BXOR(1) test failed\n" );
	    }
	    if (soutbuf[1]) {
		errs++;
		fprintf( stderr, "short BXOR(0) test failed\n" );
	    }
	    if (soutbuf[2] != ((size % 2) ? (short)0xc3c3 : (short)0xffff)) {
		errs++;
		fprintf( stderr, "short BXOR(>) test failed\n" );
	    }
	}
    }

    /* unsigned short */
    MTestPrintfMsg( 10, "Reduce of MPI_UNSIGNED_SHORT\n" );
    usinbuf[0] = 0xffff;
    usinbuf[1] = 0;
    usinbuf[2] = (rank > 0) ? 0x3c3c : 0xc3c3;

    usoutbuf[0] = 0;
    usoutbuf[1] = 1;
    usoutbuf[2] = 1;
    rc = MPI_Reduce( usinbuf, usoutbuf, 3, MPI_UNSIGNED_SHORT, MPI_BXOR, 0, comm );
    if (rc) {
	MTestPrintErrorMsg( "MPI_BXOR and MPI_UNSIGNED_SHORT", rc );
	errs++;
    }
    else {
	if (rank == 0) {
	    if (usoutbuf[0] != ((size % 2) ? 0xffff : 0)) {
		errs++;
		fprintf( stderr, "short BXOR(1) test failed\n" );
	    }
	    if (usoutbuf[1]) {
		errs++;
		fprintf( stderr, "short BXOR(0) test failed\n" );
	    }
	    if (usoutbuf[2] != ((size % 2) ? 0xc3c3 : 0xffff)) {
		errs++;
		fprintf( stderr, "short BXOR(>) test failed\n" );
	    }
	}
    }

    /* unsigned */
    MTestPrintfMsg( 10, "Reduce of MPI_UNSIGNED\n" );
    uinbuf[0] = 0xffffffff;
    uinbuf[1] = 0;
    uinbuf[2] = (rank > 0) ? 0x3c3c3c3c : 0xc3c3c3c3;

    uoutbuf[0] = 0;
    uoutbuf[1] = 1;
    uoutbuf[2] = 1;
    rc = MPI_Reduce( uinbuf, uoutbuf, 3, MPI_UNSIGNED, MPI_BXOR, 0, comm );
    if (rc) {
	MTestPrintErrorMsg( "MPI_BXOR and MPI_UNSIGNED", rc );
	errs++;
    }
    else {
	if (rank == 0) {
	    if (uoutbuf[0] != ((size % 2) ? 0xffffffff : 0)) {
		errs++;
		fprintf( stderr, "unsigned BXOR(1) test failed\n" );
	    }
	    if (uoutbuf[1]) {
		errs++;
		fprintf( stderr, "unsigned BXOR(0) test failed\n" );
	    }
	    if (uoutbuf[2] != ((size % 2) ? 0xc3c3c3c3 : 0xffffffff)) {
		errs++;
		fprintf( stderr, "unsigned BXOR(>) test failed\n" );
	    }
	}
    }

    /* int */
    MTestPrintfMsg( 10, "Reduce of MPI_INT\n" );
    iinbuf[0] = 0xffffffff;
    iinbuf[1] = 0;
    iinbuf[2] = (rank > 0) ? 0x3c3c3c3c : 0xc3c3c3c3;

    ioutbuf[0] = 0;
    ioutbuf[1] = 1;
    ioutbuf[2] = 1;
    rc = MPI_Reduce( iinbuf, ioutbuf, 3, MPI_INT, MPI_BXOR, 0, comm );
    if (rc) {
	MTestPrintErrorMsg( "MPI_BXOR and MPI_INT", rc );
	errs++;
    }
    else {
	if (rank == 0) {
	    if (ioutbuf[0] != ((size % 2) ? 0xffffffff : 0)) {
		errs++;
		fprintf( stderr, "int BXOR(1) test failed\n" );
	    }
	    if (ioutbuf[1]) {
		errs++;
		fprintf( stderr, "int BXOR(0) test failed\n" );
	    }
	    if (ioutbuf[2] != ((size % 2) ? 0xc3c3c3c3 : 0xffffffff)) {
		errs++;
		fprintf( stderr, "int BXOR(>) test failed\n" );
	    }
	}
    }

    /* long */
    MTestPrintfMsg( 10, "Reduce of MPI_LONG\n" );
    linbuf[0] = 0xffffffff;
    linbuf[1] = 0;
    linbuf[2] = (rank > 0) ? 0x3c3c3c3c : 0xc3c3c3c3;

    loutbuf[0] = 0;
    loutbuf[1] = 1;
    loutbuf[2] = 1;
    rc = MPI_Reduce( linbuf, loutbuf, 3, MPI_LONG, MPI_BXOR, 0, comm );
    if (rc) {
	MTestPrintErrorMsg( "MPI_BXOR and MPI_LONG", rc );
	errs++;
    }
    else {
	if (rank == 0) {
	    if (loutbuf[0] != ((size % 2) ? 0xffffffff : 0)) {
		errs++;
		fprintf( stderr, "long BXOR(1) test failed\n" );
	    }
	    if (loutbuf[1]) {
		errs++;
		fprintf( stderr, "long BXOR(0) test failed\n" );
	    }
	    if (loutbuf[2] != ((size % 2) ? 0xc3c3c3c3 : 0xffffffff)) {
		errs++;
		fprintf( stderr, "long BXOR(>) test failed\n" );
	    }
	}
    }

    /* unsigned long */
    MTestPrintfMsg( 10, "Reduce of MPI_UNSIGNED_LONG\n" );
    ulinbuf[0] = 0xffffffff;
    ulinbuf[1] = 0;
    ulinbuf[2] = (rank > 0) ? 0x3c3c3c3c : 0xc3c3c3c3;

    uloutbuf[0] = 0;
    uloutbuf[1] = 1;
    uloutbuf[2] = 1;
    rc = MPI_Reduce( ulinbuf, uloutbuf, 3, MPI_UNSIGNED_LONG, MPI_BXOR, 0, comm );
    if (rc) {
	MTestPrintErrorMsg( "MPI_BXOR and MPI_UNSIGNED_LONG", rc );
	errs++;
    }
    else {
	if (rank == 0) {
	    if (uloutbuf[0] != ((size % 2) ? 0xffffffff : 0)) {
		errs++;
		fprintf( stderr, "unsigned long BXOR(1) test failed\n" );
	    }
	    if (uloutbuf[1]) {
		errs++;
		fprintf( stderr, "unsigned long BXOR(0) test failed\n" );
	    }
	    if (uloutbuf[2] != ((size % 2) ? 0xc3c3c3c3 : 0xffffffff)) {
		errs++;
		fprintf( stderr, "unsigned long BXOR(>) test failed\n" );
	    }
	}
    }

#ifdef HAVE_LONG_LONG
    {
	long long llinbuf[3], lloutbuf[3];
    /* long long */
    llinbuf[0] = 0xffffffff;
    llinbuf[1] = 0;
    llinbuf[2] = (rank > 0) ? 0x3c3c3c3c : 0xc3c3c3c3;

    lloutbuf[0] = 0;
    lloutbuf[1] = 1;
    lloutbuf[2] = 1;
    if (MPI_LONG_LONG != MPI_DATATYPE_NULL) {
	MTestPrintfMsg( 10, "Reduce of MPI_LONG_LONG\n" );
	rc = MPI_Reduce( llinbuf, lloutbuf, 3, MPI_LONG_LONG, MPI_BXOR, 0, comm );
	if (rc) {
	    MTestPrintErrorMsg( "MPI_BXOR and MPI_LONG_LONG", rc );
	    errs++;
	}
	else {
	    if (rank == 0) {
		if (lloutbuf[0] != ((size % 2) ? 0xffffffff : 0)) {
		    errs++;
		    fprintf( stderr, "long long BXOR(1) test failed\n" );
		}
		if (lloutbuf[1]) {
		    errs++;
		    fprintf( stderr, "long long BXOR(0) test failed\n" );
		}
		if (lloutbuf[2] != ((size % 2) ? 0xc3c3c3c3 : 0xffffffff)) {
		    errs++;
		    fprintf( stderr, "long long BXOR(>) test failed\n" );
		}
	    }
	}
    }
    }
#endif

    MPI_Errhandler_set( comm, MPI_ERRORS_ARE_FATAL );
    MTest_Finalize( errs );
    MPI_Finalize();
    return 0;
}
Пример #8
0
int main(int argc, char *argv[])
{
    int errs = 0, err;
    int dsize;
    MPI_Datatype newtype;

    MTest_Init(&argc, &argv);

    /* Check the most likely cases.  Note that it is an error to
     * free the type returned by MPI_Type_match_size.  Also note
     * that it is an error to request a size not supported by the compiler,
     * so Type_match_size should generate an error in that case */
    MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);

    err = MPI_Type_match_size(MPI_TYPECLASS_REAL, sizeof(float), &newtype);
    if (err) {
        errs++;
        MTestPrintErrorMsg("Float: ", err);
    }
    else {
        err = MPI_Type_size(newtype, &dsize);
        if (err) {
            errs++;
            MTestPrintErrorMsg("Float type: ", err);
        }
        else {
            if (dsize != sizeof(float)) {
                errs++;
                printf("Unexpected size for float (%d != %d)\n", dsize, (int) sizeof(float));
            }
        }
    }

    err = MPI_Type_match_size(MPI_TYPECLASS_REAL, sizeof(double), &newtype);
    if (err) {
        errs++;
        MTestPrintErrorMsg("Double: ", err);
    }
    else {
        MPI_Type_size(newtype, &dsize);
        if (dsize != sizeof(double)) {
            errs++;
            printf("Unexpected size for double\n");
        }
    }
#ifdef HAVE_LONG_DOUBLE
    err = MPI_Type_match_size(MPI_TYPECLASS_REAL, sizeof(long double), &newtype);
    if (err) {
        errs++;
        MTestPrintErrorMsg("Long double: ", err);
    }
    else {
        MPI_Type_size(newtype, &dsize);
        if (dsize != sizeof(long double)) {
            errs++;
            printf("Unexpected size for long double\n");
        }
    }
#endif

    err = MPI_Type_match_size(MPI_TYPECLASS_INTEGER, sizeof(short), &newtype);
    if (err) {
        errs++;
        MTestPrintErrorMsg("Short: ", err);
    }
    else {
        MPI_Type_size(newtype, &dsize);
        if (dsize != sizeof(short)) {
            errs++;
            printf("Unexpected size for short\n");
        }
    }

    err = MPI_Type_match_size(MPI_TYPECLASS_INTEGER, sizeof(int), &newtype);
    if (err) {
        errs++;
        MTestPrintErrorMsg("Int: ", err);
    }
    else {
        MPI_Type_size(newtype, &dsize);
        if (dsize != sizeof(int)) {
            errs++;
            printf("Unexpected size for int\n");
        }
    }

    err = MPI_Type_match_size(MPI_TYPECLASS_INTEGER, sizeof(long), &newtype);
    if (err) {
        errs++;
        MTestPrintErrorMsg("Long: ", err);
    }
    else {
        MPI_Type_size(newtype, &dsize);
        if (dsize != sizeof(long)) {
            errs++;
            printf("Unexpected size for long\n");
        }
    }
#ifdef HAVE_LONG_LONG
    err = MPI_Type_match_size(MPI_TYPECLASS_INTEGER, sizeof(long long), &newtype);
    if (err) {
        errs++;
        MTestPrintErrorMsg("Long long: ", err);
    }
    else {
        MPI_Type_size(newtype, &dsize);
        if (dsize != sizeof(long long)) {
            errs++;
            printf("Unexpected size for long long\n");
        }
    }
#endif

    /* COMPLEX is a FORTRAN type.  The MPICH Type_match_size attempts
     * to give a valid datatype, but if Fortran is not available,
     * MPI_COMPLEX and MPI_DOUBLE_COMPLEX are not supported.
     * Allow this case by testing for MPI_DATATYPE_NULL */
    if (MPI_COMPLEX != MPI_DATATYPE_NULL) {
        err = MPI_Type_match_size(MPI_TYPECLASS_COMPLEX, 2 * sizeof(float), &newtype);
        if (err) {
            errs++;
            MTestPrintErrorMsg("Complex: ", err);
        }
        else {
            MPI_Type_size(newtype, &dsize);
            if (dsize != 2 * sizeof(float)) {
                errs++;
                printf("Unexpected size for complex\n");
            }
        }
    }

    if (MPI_COMPLEX != MPI_DATATYPE_NULL && MPI_DOUBLE_COMPLEX != MPI_DATATYPE_NULL) {
        err = MPI_Type_match_size(MPI_TYPECLASS_COMPLEX, 2 * sizeof(double), &newtype);
        if (err) {
            errs++;
            MTestPrintErrorMsg("Double complex: ", err);
        }
        else {
            MPI_Type_size(newtype, &dsize);
            if (dsize != 2 * sizeof(double)) {
                errs++;
                printf("Unexpected size for double complex\n");
            }
        }
    }

    MTest_Finalize(errs);
    MPI_Finalize();
    return 0;
}