コード例 #1
0
ファイル: allred.c プロジェクト: NexMirror/MPICH
MTEST_THREAD_RETURN_TYPE test_iallred(void *arg)
{
    MPI_Request req;
    int tid = *(int *) arg;
    int buf[BUF_SIZE];

    MTEST_VG_MEM_INIT(buf, BUF_SIZE * sizeof(int));

    if (tid == rank)
        MTestSleep(1);
    MPI_Allreduce(MPI_IN_PLACE, buf, BUF_SIZE, MPI_INT, MPI_BAND, comms[tid]);

    return (MTEST_THREAD_RETURN_TYPE) 0;
}
コード例 #2
0
ファイル: winerr.c プロジェクト: ParaStation/psmpi2
int main(int argc, char *argv[])
{
    int err;
    int buf[2];
    MPI_Win win;
    MPI_Comm comm;
    MPI_Errhandler newerr, olderr;

    MTEST_VG_MEM_INIT(buf, 2 * sizeof(int));

    MTest_Init(&argc, &argv);
    comm = MPI_COMM_WORLD;
    MPI_Win_create_errhandler(weh, &newerr);

    MPI_Win_create(buf, 2 * sizeof(int), sizeof(int), MPI_INFO_NULL, comm, &win);

    mywin = win;
    MPI_Win_get_errhandler(win, &olderr);
    if (olderr != MPI_ERRORS_ARE_FATAL) {
        errs++;
        printf("Expected errors are fatal\n");
    }

    MPI_Win_set_errhandler(win, newerr);

    expected_err_class = MPI_ERR_RANK;
    err = MPI_Put(buf, 1, MPI_INT, -5, 0, 1, MPI_INT, win);
    if (calls != 1) {
        errs++;
        printf("newerr not called\n");
        calls = 1;
    }
    expected_err_class = MPI_ERR_OTHER;
    MPI_Win_call_errhandler(win, MPI_ERR_OTHER);
    if (calls != 2) {
        errs++;
        printf("newerr not called (2)\n");
    }

    MPI_Win_free(&win);
    MPI_Errhandler_free(&newerr);

    MTest_Finalize(errs);
    return MTestReturnValue(errs);
}
コード例 #3
0
ファイル: isendirecv.c プロジェクト: NexMirror/MPICH
int main(int argc, char *argv[])
{
    int errors = 0;
    int elems = 20;
    int rank, nproc, dest, i;
    float *in_buf, *out_buf;
    MPI_Comm comm;
    MPI_Request *reqs;

    MTest_Init(&argc, &argv);

    comm = MPI_COMM_WORLD;
    MPI_Comm_rank(comm, &rank);
    MPI_Comm_size(comm, &nproc);

    reqs = (MPI_Request *) malloc(2 * nproc * sizeof(MPI_Request));
    in_buf = (float *) malloc(elems * nproc * sizeof(float));
    out_buf = (float *) malloc(elems * nproc * sizeof(float));
    MTEST_VG_MEM_INIT(out_buf, elems * nproc * sizeof(float));

    for (i = 0; i < nproc; i++) {
        MPI_Irecv(&in_buf[elems * i], elems, MPI_FLOAT, i, 0, comm, &reqs[i]);
    }

    for (i = 0; i < nproc; i++) {
        MPI_Isend(&out_buf[elems * i], elems, MPI_FLOAT, i, 0, comm, &reqs[i + nproc]);
    }

    MPI_Waitall(nproc * 2, reqs, MPI_STATUSES_IGNORE);

    free(reqs);
    free(in_buf);
    free(out_buf);
    MTest_Finalize(errors);
    MPI_Finalize();
    return 0;

}
コード例 #4
0
ファイル: opmin.c プロジェクト: NexMirror/MPICH
/*
 * This test looks at the handling of char and types that  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 rank, size;
    MPI_Comm comm;
    char cinbuf[3], coutbuf[3];
    signed char scinbuf[3], scoutbuf[3];
    unsigned char ucinbuf[3], ucoutbuf[3];

    MTest_Init(&argc, &argv);

    comm = MPI_COMM_WORLD;

    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 & 0x7f);

    coutbuf[0] = 0;
    coutbuf[1] = 1;
    coutbuf[2] = 1;
    MPI_Reduce(cinbuf, coutbuf, 3, MPI_CHAR, MPI_MIN, 0, comm);
    if (rank == 0) {
        if (coutbuf[0] != 1) {
            errs++;
            fprintf(stderr, "char MIN(1) test failed\n");
        }
        if (coutbuf[1] != 0) {
            errs++;
            fprintf(stderr, "char MIN(0) test failed\n");
        }
        if (coutbuf[2] != 0) {
            errs++;
            fprintf(stderr, "char MIN(>) 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 & 0x7f);

    scoutbuf[0] = 0;
    scoutbuf[1] = 1;
    scoutbuf[2] = 1;
    MPI_Reduce(scinbuf, scoutbuf, 3, MPI_SIGNED_CHAR, MPI_MIN, 0, comm);
    if (rank == 0) {
        if (scoutbuf[0] != 1) {
            errs++;
            fprintf(stderr, "signed char MIN(1) test failed\n");
        }
        if (scoutbuf[1] != 0) {
            errs++;
            fprintf(stderr, "signed char MIN(0) test failed\n");
        }
        if (scoutbuf[2] != 0) {
            errs++;
            fprintf(stderr, "signed char MIN(>) test failed\n");
        }
    }

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

    ucoutbuf[0] = 0;
    ucoutbuf[1] = 1;
    ucoutbuf[2] = 1;
    MPI_Reduce(ucinbuf, ucoutbuf, 3, MPI_UNSIGNED_CHAR, MPI_MIN, 0, comm);
    if (rank == 0) {
        if (ucoutbuf[0] != 1) {
            errs++;
            fprintf(stderr, "unsigned char MIN(1) test failed\n");
        }
        if (ucoutbuf[1]) {
            errs++;
            fprintf(stderr, "unsigned char MIN(0) test failed\n");
        }
        if (ucoutbuf[2] != 0) {
            errs++;
            fprintf(stderr, "unsigned char MIN(>) 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;

        ldoutbuf[0] = 0;
        ldoutbuf[1] = 1;
        ldoutbuf[2] = 1;
        if (MPI_LONG_DOUBLE != MPI_DATATYPE_NULL) {
            MTestPrintfMsg(10, "Reduce of MPI_LONG_DOUBLE\n");
            MPI_Reduce(ldinbuf, ldoutbuf, 3, MPI_LONG_DOUBLE, MPI_MIN, 0, comm);
            if (rank == 0) {
                if (ldoutbuf[0] != 1) {
                    errs++;
                    fprintf(stderr, "long double MIN(1) test failed\n");
                }
                if (ldoutbuf[1] != 0.0) {
                    errs++;
                    fprintf(stderr, "long double MIN(0) test failed\n");
                }
                if (ldoutbuf[2] != 0.0) {
                    errs++;
                    fprintf(stderr, "long double MIN(>) test failed\n");
                }
            }
        }
    }
#endif /* HAVE_LONG_DOUBLE */

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

        lloutbuf[0] = 0;
        lloutbuf[1] = 1;
        lloutbuf[2] = 1;
        if (MPI_LONG_LONG != MPI_DATATYPE_NULL) {
            MTestPrintfMsg(10, "Reduce of MPI_LONG_LONG\n");
            MPI_Reduce(llinbuf, lloutbuf, 3, MPI_LONG_LONG, MPI_MIN, 0, comm);
            if (rank == 0) {
                if (lloutbuf[0] != 1) {
                    errs++;
                    fprintf(stderr, "long long MIN(1) test failed\n");
                }
                if (lloutbuf[1] != 0) {
                    errs++;
                    fprintf(stderr, "long long MIN(0) test failed\n");
                }
                if (lloutbuf[2] != 0) {
                    errs++;
                    fprintf(stderr, "long long MIN(>) test failed\n");
                }
            }
        }
    }
#endif /* HAVE_LONG_LONG */

    MTest_Finalize(errs);
    MPI_Finalize();
    return 0;
}
コード例 #5
0
ファイル: oplxor.c プロジェクト: ParaStation/psmpi2
/*
 * 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);
}
コード例 #6
0
ファイル: getpartelm.c プロジェクト: NexMirror/MPICH
int main(int argc, char *argv[])
{
    int errs = 0;
    MPI_Datatype outtype, oldtypes[2];
    MPI_Aint offsets[2];
    int blklens[2];
    MPI_Comm comm;
    int size, rank, src, dest, tag;

    MTest_Init(&argc, &argv);

    comm = MPI_COMM_WORLD;

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

    if (size < 2) {
        errs++;
        printf("This test requires at least 2 processes\n");
        MPI_Abort(MPI_COMM_WORLD, 1);
    }

    src = 0;
    dest = 1;

    if (rank == src) {
        int buf[128], position, cnt;
        MTEST_VG_MEM_INIT(buf, 128 * sizeof(buf[0]));
        /* sender */

        /* Create a datatype and send it (multiple of sizeof(int)) */
        /* Create a send struct type */
        oldtypes[0] = MPI_INT;
        oldtypes[1] = MPI_CHAR;
        blklens[0] = 1;
        blklens[1] = 4 * sizeof(int);
        offsets[0] = 0;
        offsets[1] = sizeof(int);
        MPI_Type_struct(2, blklens, offsets, oldtypes, &outtype);
        MPI_Type_commit(&outtype);

        buf[0] = 4 * sizeof(int);
        /* printf("About to send to %d\n", dest); */
        MPI_Send(buf, 1, outtype, dest, 0, comm);
        MPI_Type_free(&outtype);

        /* Create a datatype and send it (not a multiple of sizeof(int)) */
        /* Create a send struct type */
        oldtypes[0] = MPI_INT;
        oldtypes[1] = MPI_CHAR;
        blklens[0] = 1;
        blklens[1] = 4 * sizeof(int) + 1;
        offsets[0] = 0;
        offsets[1] = sizeof(int);
        MPI_Type_struct(2, blklens, offsets, oldtypes, &outtype);
        MPI_Type_commit(&outtype);

        buf[0] = 4 * sizeof(int) + 1;
        MPI_Send(buf, 1, outtype, dest, 1, comm);
        MPI_Type_free(&outtype);

        /* Pack data and send as packed */
        position = 0;
        cnt = 7;
        MPI_Pack(&cnt, 1, MPI_INT, buf, 128 * sizeof(int), &position, comm);
        MPI_Pack((void *) "message", 7, MPI_CHAR, buf, 128 * sizeof(int), &position, comm);
        MPI_Send(buf, position, MPI_PACKED, dest, 2, comm);
    }
    else if (rank == dest) {
        MPI_Status status;
        int buf[128], i, elms, count;

        /* Receiver */
        /* Create a receive struct type */
        oldtypes[0] = MPI_INT;
        oldtypes[1] = MPI_CHAR;
        blklens[0] = 1;
        blklens[1] = 256;
        offsets[0] = 0;
        offsets[1] = sizeof(int);
        MPI_Type_struct(2, blklens, offsets, oldtypes, &outtype);
        MPI_Type_commit(&outtype);

        for (i = 0; i < 3; i++) {
            tag = i;
            /* printf("about to receive tag %d from %d\n", i, src); */
            MPI_Recv(buf, 1, outtype, src, tag, comm, &status);
            MPI_Get_elements(&status, outtype, &elms);
            if (elms != buf[0] + 1) {
                errs++;
                printf("For test %d, Get elements gave %d but should be %d\n", i, elms, buf[0] + 1);
            }
            MPI_Get_count(&status, outtype, &count);
            if (count != MPI_UNDEFINED) {
                errs++;
                printf("For partial send, Get_count did not return MPI_UNDEFINED\n");
            }
        }
        MPI_Type_free(&outtype);
    }

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

}
コード例 #7
0
ファイル: oplor.c プロジェクト: NexMirror/MPICH
/*
 * 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;
}
コード例 #8
0
ファイル: errinstatwa.c プロジェクト: ParaStation/psmpi2
int main(int argc, char *argv[])
{
    int errs = 0;
    MPI_Comm comm;
    MPI_Request r[2];
    MPI_Status s[2];
    int errval, errclass;
    int b1[20], b2[20], rank, size, src, dest, i;

    MTEST_VG_MEM_INIT(b1, 20 * sizeof(int));
    MTEST_VG_MEM_INIT(b2, 20 * sizeof(int));

    MTest_Init(&argc, &argv);

    /* Create some receive requests.  tags 0-9 will succeed, tags 10-19
     * will be used for ERR_TRUNCATE (fewer than 20 messages will be used) */
    comm = MPI_COMM_WORLD;

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

    src = 1;
    dest = 0;
    if (rank == dest) {
        MPI_Errhandler_set(comm, MPI_ERRORS_RETURN);
        errval = MPI_Irecv(b1, 10, MPI_INT, src, 0, comm, &r[0]);
        if (errval) {
            errs++;
            MTestPrintError(errval);
            printf("Error returned from Irecv\n");
        }
        errval = MPI_Irecv(b2, 10, MPI_INT, src, 10, comm, &r[1]);
        if (errval) {
            errs++;
            MTestPrintError(errval);
            printf("Error returned from Irecv\n");
        }

        /* Wait for Irecvs to be posted before the sender calls send.  This
         * prevents the operation from completing and returning an error in the
         * Irecv. */
        errval = MPI_Recv(NULL, 0, MPI_INT, src, 100, comm, MPI_STATUS_IGNORE);
        if (errval) {
            errs++;
            MTestPrintError(errval);
            printf("Error returned from Recv\n");
        }

        if (errval) {
            errs++;
            MTestPrintError(errval);
            printf("Error returned from Barrier\n");
        }
        for (i = 0; i < 2; i++) {
            s[i].MPI_ERROR = -1;
        }
        errval = MPI_Waitall(2, r, s);
        MPI_Error_class(errval, &errclass);
        if (errclass != MPI_ERR_IN_STATUS) {
            errs++;
            printf("Did not get ERR_IN_STATUS in Waitall\n");
        } else {
            /* Check for success */
            /* We allow ERR_PENDING (neither completed nor in error) in case
             * the MPI implementation exits the Waitall when an error
             * is detected. Thanks to Jim Hoekstra of Iowa State University
             * and Kim McMahon for finding this bug in the test. */
            for (i = 0; i < 2; i++) {
                if (s[i].MPI_TAG < 10 && (s[i].MPI_ERROR != MPI_SUCCESS &&
                                          s[i].MPI_ERROR != MPI_ERR_PENDING)) {
                    char msg[MPI_MAX_ERROR_STRING];
                    int msglen = MPI_MAX_ERROR_STRING;
                    errs++;
                    printf("correct msg had error code %d\n", s[i].MPI_ERROR);
                    MPI_Error_string(s[i].MPI_ERROR, msg, &msglen);
                    printf("Error message was %s\n", msg);
                } else if (s[i].MPI_TAG >= 10 && s[i].MPI_ERROR == MPI_SUCCESS) {
                    errs++;
                    printf("truncated msg had MPI_SUCCESS\n");
                }
            }
        }

    } else if (rank == src) {
        /* Wait for Irecvs to be posted before the sender calls send */
        MPI_Ssend(NULL, 0, MPI_INT, dest, 100, comm);

        MPI_Send(b1, 10, MPI_INT, dest, 0, comm);
        MPI_Send(b2, 11, MPI_INT, dest, 10, comm);
    }

    MTest_Finalize(errs);
    return MTestReturnValue(errs);
}
コード例 #9
0
ファイル: sendrecv3.c プロジェクト: ParaStation/psmpi2
int main(int argc, char *argv[])
{
    int errs = 0;
    int rank, size, source, dest, partner;
    int i, testnum;
    double tsend;
    static int msgsizes[] = { 100, 1000, 10000, 100000, -1 };
    static int nmsgs[] = { 100, 10, 10, 4 };
    MPI_Comm comm;

    MTest_Init(&argc, &argv);

    comm = MPI_COMM_WORLD;

    MPI_Comm_rank(comm, &rank);
    MPI_Comm_size(comm, &size);
    source = 0;
    dest = 1;
    if (size < 2) {
        printf("This test requires at least 2 processes\n");
        MPI_Abort(MPI_COMM_WORLD, 1);
    }

    for (testnum = 0; msgsizes[testnum] > 0; testnum++) {
        if (rank == source || rank == dest) {
            int nmsg = nmsgs[testnum];
            int msgSize = msgsizes[testnum];
            MPI_Request r[MAX_NMSGS];
            int *buf[MAX_NMSGS];

            for (i = 0; i < nmsg; i++) {
                buf[i] = (int *) malloc(msgSize * sizeof(int));
                if (!buf[i]) {
                    fprintf(stderr, "Unable to allocate %d bytes\n", msgSize);
                    MPI_Abort(MPI_COMM_WORLD, 1);
                }
                MTEST_VG_MEM_INIT(buf[i], msgSize * sizeof(int));
            }
            partner = (rank + 1) % size;

            MPI_Sendrecv(MPI_BOTTOM, 0, MPI_INT, partner, 10,
                         MPI_BOTTOM, 0, MPI_INT, partner, 10, comm, MPI_STATUS_IGNORE);
            /* Try to fill up the outgoing message buffers */
            for (i = 0; i < nmsg; i++) {
                MPI_Isend(buf[i], msgSize, MPI_INT, partner, testnum, comm, &r[i]);
            }
            for (i = 0; i < nmsg; i++) {
                MPI_Recv(buf[i], msgSize, MPI_INT, partner, testnum, comm, MPI_STATUS_IGNORE);
            }
            MPI_Waitall(nmsg, r, MPI_STATUSES_IGNORE);

            /* Repeat the test, but make one of the processes sleep */
            MPI_Sendrecv(MPI_BOTTOM, 0, MPI_INT, partner, 10,
                         MPI_BOTTOM, 0, MPI_INT, partner, 10, comm, MPI_STATUS_IGNORE);
            if (rank == dest)
                MTestSleep(1);
            /* Try to fill up the outgoing message buffers */
            tsend = MPI_Wtime();
            for (i = 0; i < nmsg; i++) {
                MPI_Isend(buf[i], msgSize, MPI_INT, partner, testnum, comm, &r[i]);
            }
            tsend = MPI_Wtime() - tsend;
            for (i = 0; i < nmsg; i++) {
                MPI_Recv(buf[i], msgSize, MPI_INT, partner, testnum, comm, MPI_STATUS_IGNORE);
            }
            MPI_Waitall(nmsg, r, MPI_STATUSES_IGNORE);

            if (tsend > 0.5) {
                printf("Isends for %d messages of size %d took too long (%f seconds)\n", nmsg,
                       msgSize, tsend);
                errs++;
            }
            MTestPrintfMsg(1, "%d Isends for size = %d took %f seconds\n", nmsg, msgSize, tsend);

            for (i = 0; i < nmsg; i++) {
                free(buf[i]);
            }
        }
    }

    MTest_Finalize(errs);
    return MTestReturnValue(errs);
}
コード例 #10
0
ファイル: multiple_ports.c プロジェクト: NexMirror/MPICH
int main(int argc, char *argv[])
{
    int num_errors = 0, total_num_errors = 0;
    int rank, size;
    char port1[MPI_MAX_PORT_NAME];
    char port2[MPI_MAX_PORT_NAME];
    MPI_Status status;
    MPI_Comm comm1, comm2;
    int verbose = 0;
    int data = 0;

    MTEST_VG_MEM_INIT(port1, MPI_MAX_PORT_NAME * sizeof(char));
    MTEST_VG_MEM_INIT(port2, MPI_MAX_PORT_NAME * sizeof(char));

    if (getenv("MPITEST_VERBOSE")) {
        verbose = 1;
    }

    MPI_Init(&argc, &argv);
    MPI_Comm_size(MPI_COMM_WORLD, &size);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);

    if (size < 3) {
        printf("Three processes needed to run this test.\n");
        MPI_Finalize();
        return 0;
    }

    if (rank == 0) {
        IF_VERBOSE(("0: opening ports.\n"));
        MPI_Open_port(MPI_INFO_NULL, port1);
        MPI_Open_port(MPI_INFO_NULL, port2);

        IF_VERBOSE(("0: opened port1: <%s>\n", port1));
        IF_VERBOSE(("0: opened port2: <%s>\n", port2));
        IF_VERBOSE(("0: sending ports.\n"));
        MPI_Send(port1, MPI_MAX_PORT_NAME, MPI_CHAR, 1, 0, MPI_COMM_WORLD);
        MPI_Send(port2, MPI_MAX_PORT_NAME, MPI_CHAR, 2, 0, MPI_COMM_WORLD);

        IF_VERBOSE(("0: accepting port2.\n"));
        MPI_Comm_accept(port2, MPI_INFO_NULL, 0, MPI_COMM_SELF, &comm2);
        IF_VERBOSE(("0: accepting port1.\n"));
        MPI_Comm_accept(port1, MPI_INFO_NULL, 0, MPI_COMM_SELF, &comm1);

        IF_VERBOSE(("0: closing ports.\n"));
        MPI_Close_port(port1);
        MPI_Close_port(port2);

        IF_VERBOSE(("0: sending 1 to process 1.\n"));
        data = 1;
        MPI_Send(&data, 1, MPI_INT, 0, 0, comm1);

        IF_VERBOSE(("0: sending 2 to process 2.\n"));
        data = 2;
        MPI_Send(&data, 1, MPI_INT, 0, 0, comm2);

        IF_VERBOSE(("0: disconnecting.\n"));
        MPI_Comm_disconnect(&comm1);
        MPI_Comm_disconnect(&comm2);
    }
    else if (rank == 1) {
        IF_VERBOSE(("1: receiving port.\n"));
        MPI_Recv(port1, MPI_MAX_PORT_NAME, MPI_CHAR, 0, 0, MPI_COMM_WORLD, &status);

        IF_VERBOSE(("1: received port1: <%s>\n", port1));
        IF_VERBOSE(("1: connecting.\n"));
        MPI_Comm_connect(port1, MPI_INFO_NULL, 0, MPI_COMM_SELF, &comm1);

        MPI_Recv(&data, 1, MPI_INT, 0, 0, comm1, &status);
        if (data != 1) {
            printf("Received %d from root when expecting 1\n", data);
            fflush(stdout);
            num_errors++;
        }

        IF_VERBOSE(("1: disconnecting.\n"));
        MPI_Comm_disconnect(&comm1);
    }
    else if (rank == 2) {
        IF_VERBOSE(("2: receiving port.\n"));
        MPI_Recv(port2, MPI_MAX_PORT_NAME, MPI_CHAR, 0, 0, MPI_COMM_WORLD, &status);

        IF_VERBOSE(("2: received port2: <%s>\n", port2));
        /* make sure process 1 has time to do the connect before this process
         * attempts to connect */
        MTestSleep(3);
        IF_VERBOSE(("2: connecting.\n"));
        MPI_Comm_connect(port2, MPI_INFO_NULL, 0, MPI_COMM_SELF, &comm2);

        MPI_Recv(&data, 1, MPI_INT, 0, 0, comm2, &status);
        if (data != 2) {
            printf("Received %d from root when expecting 2\n", data);
            fflush(stdout);
            num_errors++;
        }

        IF_VERBOSE(("2: disconnecting.\n"));
        MPI_Comm_disconnect(&comm2);
    }

    MPI_Barrier(MPI_COMM_WORLD);

    MPI_Reduce(&num_errors, &total_num_errors, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
    if (rank == 0) {
        if (total_num_errors) {
            printf(" Found %d errors\n", total_num_errors);
        }
        else {
            printf(" No Errors\n");
        }
        fflush(stdout);
    }
    MPI_Finalize();
    return total_num_errors;
}