コード例 #1
0
ファイル: test.c プロジェクト: dmlb2000/nwchem-cml
static void Hello()
/*
  Everyone says hi to everyone else
*/
{
    char buf[30];
    long lenbuf = sizeof buf;
    long type=19 | MSGCHR;
    long node, kode, nodefrom, lenmes;
    long sync = 1;

    if (NODEID_() == 0) {
        (void) printf("Hello test ... show network integrity\n----------\n\n");
        (void) fflush(stdout);
    }

    for (node = 0; node<NNODES_(); node++) {
        if (node == NODEID_()) {
            for (kode = 0; kode<NNODES_(); kode++) {
                (void) sprintf(buf, "Hello to %ld from %ld", (long)kode, (long)NODEID_());
                if (node != kode)
                    SND_(&type, buf, &lenbuf, &kode, &sync);
            }
        }
        else {
            RCV_(&type, buf, &lenbuf, &lenmes, &node, &nodefrom, &sync);
            (void) printf("me=%ld, from=%ld: %s\n",(long)NODEID_(), (long)node, buf);
            (void) fflush(stdout);
        }
    }

}
コード例 #2
0
ファイル: misc.c プロジェクト: dmlb2000/nwchem-cml
void Error(char *string, Integer code)
{
    fprintf(stdout, FMT_INT ": %s " FMT_INT " (%#lx).\n",
            NODEID_(), string, code, (long unsigned int)code);
    fflush(stdout);
    fprintf(stderr, FMT_INT ": %s " FMT_INT " (%#lx).\n",
            NODEID_(), string, code, (long unsigned int)code);

    finalize_nxtval(); /* clean nxtval resources */
    MPI_Abort(MPI_COMM_WORLD,(int)code);
}
コード例 #3
0
ファイル: test.c プロジェクト: dmlb2000/nwchem-cml
static void TestProbe()
/*
  Process 0 sleeps for 20 seconds and then sends each
  process a message.  The other processes sleep for periods
  of 2 seconds and probes until it gets a message.  All processes
  respond to process 0 which recieves using a wildcard probe.
  */
{
    long type_syn = 32;
    long type_msg = 33;
    long type_ack = 34;
    long me = NODEID_();
    char buf;
    long lenbuf = sizeof buf;
    long sync = 1;


    if (me == 0) {
        (void) printf("Probe test ... processes should sleep for 20s only\n");
        (void) printf("----------\n\n");
        (void) fflush(stdout);
    }

    SYNCH_(&type_syn);

    if (me == 0) {
        long nproc = NNODES_();
        long anyone = -1;
        long ngot = 0;
        long node;

        (void) sleep((unsigned) 20);

        for (node=1; node<nproc; node++) {
            SND_(&type_msg, &buf, &lenbuf, &node, &sync);
            (void) printf("    Sent message to %ld\n", (long)node);
            (void) fflush(stdout);
        }

        while (ngot < (nproc-1))
            if (PROBE_(&type_ack, &anyone)) {
                RCV_(&type_ack, &buf, &lenbuf, &lenbuf, &anyone, &node, &sync);
                (void) printf("    Got response from %ld\n", (long)node);
                (void) fflush(stdout);
                ngot++;
            }
    }
    else {
        long node = 0;
        while (!PROBE_(&type_msg, &node)) {
            (void) printf("    Node %ld sleeping\n", (long)me);
            (void) fflush(stdout);
            (void) sleep((unsigned) 2);
        }
        RCV_(&type_msg, &buf, &lenbuf, &lenbuf, &node, &node, &sync);
        SND_(&type_ack, &buf, &lenbuf, &node, &sync);
    }

    SYNCH_(&type_syn);
}
コード例 #4
0
ファイル: tcgmsg.c プロジェクト: carriercomm/ix
void Setup(ArgStruct *p)
{
    long nprocs;

    nprocs      = NNODES_();
    p->prot.nid = NODEID_();
    {
        char s[255];
        gethostname(s,253);
        printf("%d: %s\n",p->prot.nid,s); fflush(stdout);
    }

    if (nprocs < 2)
    {
        printf("Need at least two processes, we have %d\n", nprocs); fflush(stdout);
        exit(-2);
    }

    p->tr = p->rcv = 0;
    if (p->prot.nid == 0) {
        p->tr = 1;
        p->prot.nbor = nprocs-1;
    } else if( p->prot.nid == nprocs-1 ) {
        p->rcv = 1;
        p->prot.nbor = 0;
    }
}
コード例 #5
0
ファイル: p2p.c プロジェクト: dmlb2000/nwchem-cml
void SND_(Integer *type, void *buf, Integer *lenbuf, Integer *node, Integer *sync)
{
    int ierr;
    int ttype = (int)*type;

    if (DEBUG_) {
        printf("SND_: node " FMT_INT " sending to " FMT_INT ", len=" FMT_INT ", type=" FMT_INT ", sync=" FMT_INT "\n",
                NODEID_(), *node, *lenbuf, *type, *sync);
        fflush(stdout);
    }

    if (*sync){
        ierr = MPI_Send(buf, (int)*lenbuf, MPI_CHAR, (int)*node, ttype,
                TCGMSG_Comm);
        tcgmsg_test_statusM("SND_:", ierr);
    }else{
        if (n_in_msg_q >= MAX_Q_LEN) {
            Error("SND:overflowing async Q limit", n_in_msg_q);
        }
        ierr = MPI_Isend(buf, (int)*lenbuf, MPI_CHAR,(int)*node, ttype,
                TCGMSG_Comm, &msg_q[n_in_msg_q].request);
        tcgmsg_test_statusM("nonblocking SND_:", ierr);

        msg_q[n_in_msg_q].node   = *node;
        msg_q[n_in_msg_q].type   = *type;
        msg_q[n_in_msg_q].lenbuf = *lenbuf;
        msg_q[n_in_msg_q].snd = 1;
    }
}
コード例 #6
0
ファイル: p2p.c プロジェクト: dmlb2000/nwchem-cml
void WAITCOM_(Integer *nodesel)
{
    int ierr, i;
    MPI_Status status;

    for (i=0; i<n_in_msg_q; i++){
        if (DEBUG_) {
            (void) printf("WAITCOM: " FMT_INT " waiting for msg to/from node " FMT_INT ", #%d\n",
                          NODEID_(), msg_q[i].node, i);
            (void) fflush(stdout);
        }
        ierr = MPI_Wait(&msg_q[i].request, &status);
        tcgmsg_test_statusM("WAITCOM:", ierr);
    }
    n_in_msg_q = 0;
}
コード例 #7
0
ファイル: p2p.c プロジェクト: dmlb2000/nwchem-cml
void RCV_(Integer *type, void *buf, Integer *lenbuf, Integer *lenmes, Integer *nodeselect, Integer *nodefrom, Integer *sync)
{
    int ierr;
    int node, count = (int)*lenbuf;
    MPI_Status status;
    MPI_Request request;

    if (*nodeselect == -1) {
        node = MPI_ANY_SOURCE;
    } else {
        node = (int)*nodeselect;
    }

    if (DEBUG_) {
        printf("RCV_: node " FMT_INT " receiving from " FMT_INT ", len=" FMT_INT ", type=" FMT_INT ", sync=" FMT_INT "\n",
                NODEID_(), *nodeselect, *lenbuf, *type, *sync);
        fflush(stdout);
    }

    if(*sync==0){
        if (n_in_msg_q >= MAX_Q_LEN) {
            Error("nonblocking RCV_: overflowing async Q limit", n_in_msg_q);
        }

        ierr = MPI_Irecv(buf, count, MPI_CHAR, node, (int)*type, TCGMSG_Comm,
                &request);
        tcgmsg_test_statusM("nonblocking RCV_:", ierr);

        *nodefrom = node; /* Get source node  */
        *lenmes =  -1L;
        msg_q[n_in_msg_q].request = request;
        msg_q[n_in_msg_q].node   = *nodeselect;
        msg_q[n_in_msg_q].type   = *type;
        msg_q[n_in_msg_q].lenbuf = *lenbuf;
        msg_q[n_in_msg_q].snd = 0;
        n_in_msg_q++;
    } else {
        ierr = MPI_Recv(buf, count, MPI_CHAR, node, (int)*type, TCGMSG_Comm,
                &status);
        tcgmsg_test_statusM("RCV_:", ierr);
        ierr = MPI_Get_count(&status, MPI_CHAR, &count);
        tcgmsg_test_statusM("RCV:Get_count:", ierr);
        *nodefrom = (Integer)status.MPI_SOURCE; 
        *lenmes   = (Integer)count;
    }
}
コード例 #8
0
ファイル: pfilecopy.c プロジェクト: dmlb2000/nwchem-cml
/** Fortran wrapper around pfilecopy */
void PFCOPY_(Integer *type, Integer *node0, char *fname, int len)
{

    char *filename;

#ifdef DEBUG 
    (void) printf("me=%d, type=%d, node0=%d, fname=%x, fname=%.8s, len=%d\n",
                  NODEID_(), *type, *node0, fname, fname, len);
#endif 

    /* Strip trailing blanks off the file name */

    while ((len > 0) && (fname[len-1] == ' ')) {
        len--;
    }
    if (len <= 0) {
        Error("pfcopy_: file name length is toast", (Integer) len);
    }

    /* Generate a NULL terminated string */

    filename = malloc( (unsigned) (len+1) );
    if (filename) {
        (void) bcopy(fname, filename, len);
        filename[len] = '\0';
    }
    else {
        Error("PFCOPY_: failed to malloc space for filename", (Integer) len);
    }

    /* Now call the C routine to do the work */

    tcgi_pfilecopy(type, node0, filename);

    (void) free(filename);
}
コード例 #9
0
ファイル: llog.c プロジェクト: liangjj/mesa_working
void LLOG_()
/*
  close and open stdin and stdout to append to a local logfile
  with the name log.<process#> in the current directory
*/
{
  char name[12];
  time_t t;

  (void) sprintf(name, "log.%03ld",NODEID_());

  (void) fflush(stdout);
  (void) fflush(stderr);

  if (freopen(name, "a", stdout) == (FILE *) NULL)
    Error("LLOG_: error re-opening stdout", (long) -1);

  if (freopen(name, "a", stderr) == (FILE *) NULL)
    Error("LLOG_: error re-opening stderr", (long) -1);

  (void) time(&t);
  (void) printf("\n\nLog file opened : %s\n\n",ctime(&t));
  (void) fflush(stdout);
}
コード例 #10
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);
}
コード例 #11
0
ファイル: capi.c プロジェクト: jeffhammond/ga
long tcg_nodeid()
{
    return NODEID_();
}
コード例 #12
0
ファイル: pfilecopy.c プロジェクト: dmlb2000/nwchem-cml
/**
 * Process node0 has a file (assumed unopened) named fname.
 * This file will be copied to all other processes which must
 * simultaneously invoke pfilecopy. Since the processes may be
 * using the same directory one probably ought to make sure
 * that each process uses a different name in the call.
 *
 *    e.g.
 *
 *    on node 0    pfilecopy(99, 0, 'argosin')
 *    on node 1    pfilecopy(99, 0, 'argosin_001')
 *    on node 2    pfilecopy(99, 0, 'argosin_002')
 */
void tcgi_pfilecopy(Integer *type, Integer *node0, char *filename)
{
    char *buffer;
    FILE *file;
    Integer length, nread=32768, len_nread=sizeof(Integer);
    Integer typenr = (*type & 32767) | MSGINT;   /* Force user type integer */
    Integer typebuf =(*type & 32767) | MSGCHR;

    if (!(buffer = malloc((unsigned) nread))) {
        Error("pfilecopy: failed to allocate the I/O buffer",nread);
    }

    if (*node0 == NODEID_()) {

        /* I have the original file ... open and check its size */

        if ((file = fopen(filename,"r")) == (FILE *) NULL) {
            (void) fprintf(stderr, "me=" FMT_INT ", filename = %s.\n",
                           NODEID_(), filename);
            Error("pfilecopy: node0 failed to open original file", *node0);
        }

        /* Quick sanity check on the length */

        (void) fseek(file, 0L, (int) 2);   /* Seek to end of file */
        length = ftell(file);              /* Find the length of file */
        (void) fseek(file, 0L, (int) 0);   /* Seek to beginning of file */
        if ( (length<0) || (length>1e12) ) {
            Error("pfilecopy: the file length is -ve or very big", length);
        }

        /* Send the file in chunks of nread bytes */

        while (nread) {
            nread = fread(buffer, 1, (int) nread, file);
            BRDCST_(&typenr, (char *) &nread, &len_nread, node0);
            typenr++;
            if (nread) {
                BRDCST_(&typebuf, buffer, &nread, node0);
                typebuf++;
            }
        }
    }
    else {

        /* Open the file for the duplicate */

        if ((file = fopen(filename,"w+")) == (FILE *) NULL) {
            (void) fprintf(stderr,"me=" FMT_INT ", filename = %s.\n",
                           NODEID_(), filename);
            Error("pfilecopy: failed to open duplicate file", *node0);
        }

        /* Receive data and write to file */

        while (nread) {
            BRDCST_(&typenr, (char *) &nread, &len_nread, node0);
            typenr++;
            if (nread) {
                BRDCST_(&typebuf, buffer, &nread, node0);
                typebuf++;
                if (nread != (Integer)fwrite(buffer, 1, (int) nread, file)) {
                    Error("pfilecopy: error data to duplicate file", nread);
                }
            }
        }
    }

    /* Tidy up the stuff we have been using */

    (void) fflush(file);
    (void) fclose(file);
    (void) free(buffer);
}