📄 test.partmods.c
字号:
/* $Header: /home/harrison/c/tcgmsg/ipcv4.0/RCS/test.c,v 1.1 91/12/06 17:27:41 harrison Exp Locker: harrison $ */#include <stdio.h>#if !defined(SEQUENT) && !defined(CONVEX)#include <memory.h>#endif#include "sndrcv.h"#include "evlog.h"extern char *memalign();#if defined(ULTRIX) || defined(SGI) || defined(NEXT) || defined(HPUX)extern void *malloc();#elseextern char *malloc();#endifextern unsigned char CheckByte();extern double DRAND48_();#if defined(SUN)extern char *sprintf();#endif#ifdef IPSC#define bzero(A,N) memset((A), 0, (N))#endifstatic void TestProbe()/* Send 100 messages from this process to random destinations all of type mtype. Receipt of these messages are acknowleged with a message of type atype. When all messages have been acked send a message of type ftype (f for finished) to process 0, but keep polling until get a message back of type ttype (t for terminate) indicating that it is OK to terminate. Note: This will NOT work with the shared memory communication mechanism (except on the KSR) and has a finite probability of deadlock over sockets or on the iPSC.*/{ long nproc = NNODES_(); long me = NODEID_(); long mtype = 10+MSGINT; long ftype = 11; long ttype = 12; long atype = 13; long anyone= -1; long len = sizeof(long);#define N_MSG 100 long nmsg = N_MSG; long nacks = N_MSG; long sync = 1; long nfinished = 0; long zero = 0; long node, nodefrom, lenmes, incoming; double start = TCGTIME_(); srandom(me*257); while (1) { if (PROBE_(&mtype, &anyone)) { RCV_(&mtype, (char *) &incoming, &len,&lenmes,&anyone,&nodefrom,&sync); SND_(&atype, (char *) &incoming, &zero, &nodefrom, &sync); } else if (nmsg) { while ((node = random() % nproc) == me) ; nmsg--; SND_(&mtype, (char *) &nmsg, &len, &node, &sync); } else if (PROBE_(&atype, &anyone)) { RCV_(&atype, (char *) &incoming,&len,&lenmes,&anyone,&nodefrom,&sync); nacks--; if (nacks == 0) { if (me == 0) nfinished++; else SND_(&ftype, (char *) &nmsg, &zero, &zero, &sync); } } else if (me == 0 && PROBE_(&ftype, &anyone)) { RCV_(&ftype, (char *) &incoming,&len,&lenmes,&anyone,&nodefrom,&sync); nfinished++; } else if (me != 0 && PROBE_(&ttype, &zero)) { RCV_(&ttype, (char *) &incoming,&len,&lenmes,&anyone,&nodefrom,&sync); break; } else if (me == 0 && nfinished == nproc) { for (node=1; node<nproc; node++) SND_(&ttype, (char *) &nmsg, &zero, &node, &sync); break; } } start = TCGTIME_() - start; if (me == 0) { (void) printf("\nProbe used %.2f seconds for 100 msgs from %ld nodes\n\n", start, nproc); (void) fflush(stdout); }}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) Error("TestGlobals: global sum failed", (long) i); } if (me == 0) { printf("global sums OK\n"); fflush(stdout); } } free((char *) itest); free((char *) dtest);} 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", kode, 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",NODEID_(), node, buf); (void) fflush(stdout); } }}static void RandList(lo, hi, list, n) long lo, hi, *list, n;/* Fill list with n random integers between lo & hi inclusively*/{ long i, ran; double dran; for (i=0; i<n; i++) { dran = DRAND48_(); ran = lo + (long) (dran * (double) (hi-lo+1)); if (ran < lo) ran = lo; if (ran > hi) ran = hi; list[i] = ran; }}void Stress()/* Stress the system by passing messages between a ranomly selected list of nodes*/{ long me = NODEID_(); long nproc = NNODES_(); long type, lenbuf, node, lenmes, nodefrom, i, j, from, to; long *list_i, *list_j, *list_n;#define N_LEN 11 static long len[N_LEN] = {0,1,2,4,8,4095,4096,4097,16367,16368,16369}; char *buf1, *buf2; long n_stress, mod; long sync = 1; from = 0; lenbuf = sizeof(long); if (me == 0) { (void) printf("Stress test ... randomly exchange messages\n-----------"); (void) printf("\n\nInput no. of messages: "); (void) fflush(stdout); if (scanf("%ld",&n_stress) != 1) Error("Stress: error reading n_stress",(long) -1); if ( (n_stress <= 0) || (n_stress > 10000) ) n_stress = 100; } type = 13 | MSGINT; BRDCST_(&type, (char *) &n_stress, &lenbuf, &from); type++; lenbuf = n_stress * sizeof(long); if ( (list_i = (long *) memalign(sizeof(long), (unsigned) lenbuf)) == (long *) NULL ) Error("Stress: failed to allocate list_i",n_stress); if ( (list_j = (long *) memalign(sizeof(long), (unsigned) lenbuf)) == (long *) NULL ) Error("Stress: failed to allocate list_j",n_stress); if ( (list_n = (long *) memalign(sizeof(long), (unsigned) lenbuf)) == (long *) NULL ) Error("Stress: failed to allocate list_n",n_stress); if ( (buf1 = malloc((unsigned) 16376)) == (char *) NULL ) Error("Stress: failed to allocate buf1", (long) 16376); if ( (buf2 = malloc((unsigned) 16376)) == (char *) NULL ) Error("Stress: failed to allocate buf2", (long) 16376); if (me == 0) { /* Make random list of node pairs and message lengths */ RandList((long) 0, (long) (NNODES_()-1), list_i, n_stress); RandList((long) 0, (long) (NNODES_()-1), list_j, n_stress); RandList((long) 0, (long) (N_LEN-1), list_n, n_stress); for (i=0; i<n_stress; i++) list_n[i] = len[list_n[i]]; } node = 0; BRDCST_(&type, (char *) list_i, &lenbuf, &node); type++; BRDCST_(&type, (char *) list_j, &lenbuf, &node); type++; BRDCST_(&type, (char *) list_n, &lenbuf, &node); type++; type = 8; for (j=0; j<16370; j++) buf1[j] = (char) (j%127); j = 0; mod = (n_stress-1)/10 + 1; for (i=0; i < n_stress; i++) { from = list_i[i]; to = list_j[i]; lenbuf = list_n[i]; type++; if ( (from < 0) || (from >= nproc) ) Error("Stress: from is out of range", from); if ( (to < 0) || (to >= nproc) ) Error("Stress: to is out of range", to); if (from == to) continue; if ( (me == 0) && (j%mod == 0) ) { (void) printf("Stress: test=%ld: from=%ld, to=%ld, len=%ld\n", i, from, to, lenbuf); (void) fflush(stdout); } j++; if (from == me) SND_(&type, buf1, &lenbuf, &to, &sync);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -