コード例 #1
0
ファイル: capi.c プロジェクト: jeffhammond/ga
void tcg_dgop(long type, double *x, long n, char *op)
{
    long atype = type;
    long an = n;
    double *ax;
    int i;

    ax = (double*)malloc(n * sizeof(double));
    for (i=0; i<n; ++i) {
        ax[i] = (double)x[i];
    }
    DGOP_(&atype, ax, &an, op, strlen(op));
    for (i=0; i<n; ++i) {
        x[i] = (double)ax[i];
    }
    free(ax);
}
コード例 #2
0
ファイル: capi.c プロジェクト: dmlb2000/nwchem-cml
void tcg_dgop(long type, double *x, long n, char *op)
{
    Integer atype = type;
    Integer an = n;
    DoublePrecision *ax;
    int i;

    ax = (DoublePrecision*)malloc(n * sizeof(DoublePrecision));
    for (i=0; i<n; ++i) {
        ax[i] = (DoublePrecision)x[i];
    }
    DGOP_(&atype, ax, &an, op, strlen(op));
    for (i=0; i<n; ++i) {
        x[i] = (double)ax[i];
    }
    free(ax);
}
コード例 #3
0
ファイル: test.c プロジェクト: dmlb2000/nwchem-cml
static void TestGlobals()
{
#define MAXLENG 256*1024
    double *dtest;
    long *itest;
    long len;
    long me = NODEID_(), nproc = NNODES_(), from=NNODES_()-1;
    long itype=3+MSGINT, dtype=4+MSGDBL;

    if (me == 0) {
        (void) printf("Global test ... test brodcast, igop and dgop\n----------\n\n");
        (void) fflush(stdout);
    }

    if (!(dtest = (double *) malloc((unsigned) (MAXLENG*sizeof(double)))))
        Error("TestGlobals: failed to allocated dtest", (long) MAXLENG);
    if (!(itest = (long *) malloc((unsigned) (MAXLENG*sizeof(long)))))
        Error("TestGlobals: failed to allocated itest", (long) MAXLENG);

    for (len=1; len<MAXLENG; len*=2) {
        long ilen = len*sizeof(long);
        long dlen = len*sizeof(double);
        long i;

        if (me == 0) {
            printf("Test length = %d ... ", len);
            fflush(stdout);
        }

        /* Test broadcast */

        if (me == (nproc-1)) {
            for (i=0; i<len; i++) {
                itest[i] = i;
                dtest[i] = (double) itest[i];
            }
        }
        else {
            for (i=0; i<len; i++) {
                itest[i] = 0;
                dtest[i] = 0.0;
            }
        }
        BRDCST_(&itype, (char *) itest, &ilen, &from);
        BRDCST_(&dtype, (char *) dtest, &dlen, &from);

        for (i=0; i<len; i++)
            if (itest[i] != i || dtest[i] != (double) i)
                Error("TestGlobal: broadcast failed", (long) i);

        if (me == 0) {
            printf("broadcast OK ...");
            fflush(stdout);
        }

        /* Test global sum */

        for (i=0; i<len; i++) {
            itest[i] = i*me;
            dtest[i] = (double) itest[i];
        }

        IGOP_(&itype, itest, &len, "+");
        DGOP_(&dtype, dtest, &len, "+");

        for (i=0; i<len; i++) {
            long iresult = i*nproc*(nproc-1)/2;
            if (itest[i] != iresult || dtest[i] != (double) iresult) {
                printf(" dt %f it %ld ir %ld \n",dtest[i],itest[i],iresult);
                Error("TestGlobals: global sum failed", (long) i);
            }
        }

        if (me == 0) {
            printf("global sums OK\n");
            fflush(stdout);
        }
    }

    free((char *) itest);
    free((char *) dtest);
}