void tcg_brdcst(long type, void *buf, long lenbuf, long originator) { long atype = type; long alenbuf = lenbuf; long aoriginator = originator; BRDCST_(&atype, buf, &alenbuf, &aoriginator); }
void tcg_brdcst(long type, void *buf, long lenbuf, long originator) { Integer atype = type; Integer alenbuf = lenbuf; Integer aoriginator = originator; BRDCST_(&atype, buf, &alenbuf, &aoriginator); }
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); }
/** * 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); }