#include #include "nmglobal.h" #include "nbench1.h" /************************* ** ASSIGNMENT ALGORITHM ** *************************/ /************* ** DoAssign ** ************** ** Perform an assignment algorithm. ** The algorithm was adapted from the step by step guide found ** in "Quantitative Decision Making for Business" (Gordon, ** Pressman, and Cohn; Prentice-Hall) ** ** ** NOTES: ** 1. Even though the algorithm distinguishes between ** ASSIGNROWS and ASSIGNCOLS, as though the two might ** be different, it does presume a square matrix. ** I.E., ASSIGNROWS and ASSIGNCOLS must be the same. ** This makes for some algorithmically-correct but ** probably non-optimal constructs. ** */ void DoAssign(void) { AssignStruct *locassignstruct; /* Local structure ptr */ long *arraybase; char *errorcontext; int systemerror; unsigned long accumtime; double iterations; /* ** Link to global structure */ locassignstruct=&global_assignstruct; /* ** Set the error context string. */ errorcontext="CPU:Assignment"; /* ** See if we need to do self adjustment code. */ if(locassignstruct->adjust==0) { /* ** Self-adjustment code. The system begins by working on 1 ** array. If it does that in no time, then two arrays ** are built. This process continues until ** enough arrays are built to handle the tolerance. */ locassignstruct->numarrays=1; while(1) { /* ** Allocate space for arrays */ arraybase=(long *) AllocateMemory(sizeof(long)* ASSIGNROWS*ASSIGNCOLS*locassignstruct->numarrays, &systemerror); if(systemerror) { ReportError(errorcontext,systemerror); FreeMemory((void *)arraybase, &systemerror); ErrorExit(); } /* ** Do an iteration of the assignment alg. If the ** elapsed time is less than or equal to the permitted ** minimum, then allocate for more arrays and ** try again. */ if(DoAssignIteration(arraybase, locassignstruct->numarrays)>global_min_ticks) break; /* We're ok...exit */ FreeMemory((void *)arraybase, &systemerror); locassignstruct->numarrays++; } } else { /* ** Allocate space for arrays */ arraybase=(long *)AllocateMemory(sizeof(long)* ASSIGNROWS*ASSIGNCOLS*locassignstruct->numarrays, &systemerror); if(systemerror) { ReportError(errorcontext,systemerror); FreeMemory((void *)arraybase, &systemerror); ErrorExit(); } } /* ** All's well if we get here. Do the tests. */ accumtime=0L; iterations=(double)0.0; do { accumtime+=DoAssignIteration(arraybase, locassignstruct->numarrays); iterations+=(double)1.0; } while(TicksToSecs(accumtime)request_secs); /* ** Clean up, calculate results, and go home. Be sure to ** show that we don't have to rerun adjustment code. */ FreeMemory((void *)arraybase,&systemerror); locassignstruct->iterspersec=iterations * (double)locassignstruct->numarrays / TicksToFracSecs(accumtime); if(locassignstruct->adjust==0) locassignstruct->adjust=1; return; } /********************** ** DoAssignIteration ** *********************** ** This routine executes one iteration of the assignment test. ** It returns the number of ticks elapsed in the iteration. */ static unsigned long DoAssignIteration(long *arraybase, unsigned long numarrays) { longptr abase; /* local pointer */ unsigned long elapsed; /* Elapsed ticks */ unsigned long i; /* ** Set up local pointer */ abase.ptrs.p=arraybase; /* ** Load up the arrays with a random table. */ LoadAssignArrayWithRand(arraybase,numarrays); /* ** Start the stopwatch */ elapsed=StartStopwatch(); /* ** Execute assignment algorithms */ for(i=0;i1) for(i=1;i