Exemplo n.º 1
0
    /*************************
    ** LoadNumArrayWithRand **
    **************************
    ** Load up an array with random longs.
    */
    private static void LoadNumArrayWithRand(int[,] array,  /* Pointer to arrays */
                                             int arraysize,
                                             int numarrays) /* # of elements in array */
    {
        int i;                                              /* Used for index */

        /*
        ** Initialize the random number generator
        */
        ByteMark.randnum(13);

        /*
        ** Load up first array with randoms
        */
        for (i = 0; i < arraysize; i++)
        {
            array[0, i] = ByteMark.randnum(0);
        }

        /*
        ** Now, if there's more than one array to load, copy the
        ** first into each of the others.
        */
        while (--numarrays > 0)
        {
            for (int j = 0; j < arraysize; j++, i++)
            {
                array[numarrays, j] = array[0, j];
            }
        }

        return;
    }
Exemplo n.º 2
0
    /*************************
    ** LoadNumArrayWithRand **
    **************************
    ** Load up an array with random longs.
    */
    private static void LoadNumArrayWithRand(int[][] array, /* Pointer to arrays */
                                             int arraysize,
                                             int numarrays) /* # of elements in array */
    {
        int i;                                              /* Used for index */

        /*
        ** Initialize the random number generator
        */
        ByteMark.randnum(13);

        /*
        ** Load up first array with randoms
        */
        for (i = 0; i < arraysize; i++)
        {
            array[0][i] = ByteMark.randnum(0);
        }

        /*
        ** Now, if there's more than one array to load, copy the
        ** first into each of the others.
        */
        for (i = 1; i < numarrays; i++)
        {
            // the old code didn't do a memcpy, so I'm not doing
            // an Array.Copy()
            for (int j = 0; j < arraysize; j++)
            {
                array[i][j] = array[0][j];
            }
        }

        return;
    }
Exemplo n.º 3
0
    /********************
    ** LoadStringArray **
    *********************
    ** Initialize the string array with random strings of
    ** varying sizes.
    ** Returns the pointer to the offset pointer array.
    ** Note that since we're creating a number of arrays, this
    ** routine builds one array, then copies it into the others.
    */
    private static void LoadStringArray(string[][] array,          /* String array */
                                        int arraysize,             /* Size of array */
                                        int numarrays)             /* # of arrays */
    {
        /*
        ** Initialize random number generator.
        */
        ByteMark.randnum(13);

        /*
        ** Load up the first array with randoms
        */

        int i;

        for (i = 0; i < arraysize; i++)
        {
            int length;

            length      = 4 + ByteMark.abs_randwc(76);
            array[0][i] = "";

            /*
            ** Fill up the string with random bytes.
            */
            StringBuilder builder = new StringBuilder(length);

            int add;
            for (add = 0; add < length; add++)
            {
                char myChar = (char)(ByteMark.abs_randwc(96) + 32);
                builder.Append(myChar);
            }
            array[0][i] = builder.ToString();
        }

        /*
        ** We now have initialized a single full array.  If there
        ** is more than one array, copy the original into the
        ** others.
        */
        int k;

        for (k = 1; k < numarrays; k++)
        {
            for (i = 0; i < arraysize; i++)
            {
                array[k][i] = array[0][i];
            }
        }
    }
Exemplo n.º 4
0
    /***************
	** LoadAssign **
	****************
	** The array given by arraybase is loaded with positive random
	** numbers.  Elements in the array are capped at 5,000,000.
	*/
    private static void LoadAssign(int[,] arraybase)
    {
        short i, j;

        /*
		** Reset random number generator so things repeat.
		*/
        ByteMark.randnum(13);

        for (i = 0; i < global.ASSIGNROWS; i++)
            for (j = 0; j < global.ASSIGNROWS; j++)
                arraybase[i, j] = ByteMark.abs_randwc(5000000);
        return;
    }
Exemplo n.º 5
0
    private static void build_problem(double[][] a, int n, double[] b)
    {
        int    i, j, k, k1;
        double rcon;

        ByteMark.randnum(13);

        for (i = 0; i < n; i++)
        {
            b[i] = (double)(ByteMark.abs_randwc(100) + 1);
            for (j = 0; j < n; j++)
            {
                if (i == j)
                {
                    a[i][j] = (double)(ByteMark.abs_randwc(1000) + 1);
                }
                else
                {
                    a[i][j] = (double)0.0;
                }
            }
        }

        for (i = 0; i < 8 * n; i++)
        {
            k  = ByteMark.abs_randwc(n);
            k1 = ByteMark.abs_randwc(n);
            if (k != k1)
            {
                if (k < k1)
                {
                    rcon = 1.0;
                }
                else
                {
                    rcon = -1.0;
                }
                for (j = 0; j < n; j++)
                {
                    a[k][j] += a[k1][j] * rcon;
                }
                b[k] += b[k1] * rcon;
            }
        }
    }
Exemplo n.º 6
0
    double DoNNET(NNetStruct locnnetstruct)
    {
        //    string errorcontext = "CPU:NNET";
        //    int systemerror = 0;
        long   accumtime  = 0;
        double iterations = 0.0;

        /*
        ** Init random number generator.
        ** NOTE: It is important that the random number generator
        **  be re-initialized for every pass through this test.
        **  The NNET algorithm uses the random number generator
        **  to initialize the net.  Results are sensitive to
        **  the initial neural net state.
        */
        ByteMark.randnum(3);

        /*
        ** Read in the input and output patterns.  We'll do this
        ** only once here at the beginning.  These values don't
        ** change once loaded.
        */
        read_data_file();

        /*
        ** See if we need to perform self adjustment loop.
        */
        if (locnnetstruct.adjust == 0)
        {
            /*
            ** Do self-adjustment.  This involves initializing the
            ** # of loops and increasing the loop count until we
            ** get a number of loops that we can use.
            */
            for (locnnetstruct.loops = 1;
                 locnnetstruct.loops < MAXNNETLOOPS;
                 locnnetstruct.loops++)
            {
                ByteMark.randnum(3);
                if (DoNNetIteration(locnnetstruct.loops) > global.min_ticks)
                {
                    break;
                }
            }
        }

        /*
        ** All's well if we get here.  Do the test.
        */
        accumtime  = 0L;
        iterations = (double)0.0;

        do
        {
            ByteMark.randnum(3);    /* Gotta do this for Neural Net */
            accumtime  += DoNNetIteration(locnnetstruct.loops);
            iterations += (double)locnnetstruct.loops;
        } while (ByteMark.TicksToSecs(accumtime) < locnnetstruct.request_secs);

        /*
        ** Clean up, calculate results, and go home.  Be sure to
        ** show that we don't have to rerun adjustment code.
        */
        locnnetstruct.iterspersec = iterations / ByteMark.TicksToFracSecs(accumtime);

        if (locnnetstruct.adjust == 0)
        {
            locnnetstruct.adjust = 1;
        }


        return(locnnetstruct.iterspersec);
    }
Exemplo n.º 7
0
    public override double Run()
    {
        int i;

        char[] Z       = new char[global.KEYLEN];
        char[] DK      = new char[global.KEYLEN];
        char[] userkey = new char[8];
        long   accumtime;
        double iterations;

        byte[] plain1;               /* First plaintext buffer */
        byte[] crypt1;               /* Encryption buffer */
        byte[] plain2;               /* Second plaintext buffer */

        /*
        ** Re-init random-number generator.
        */
        ByteMark.randnum(3);

        /*
        ** Build an encryption/decryption key
        */
        for (i = 0; i < 8; i++)
        {
            userkey[i] = (char)(ByteMark.abs_randwc(60000) & 0xFFFF);
        }
        for (i = 0; i < global.KEYLEN; i++)
        {
            Z[i] = (char)0;
        }

        /*
        ** Compute encryption/decryption subkeys
        */
        en_key_idea(userkey, Z);
        de_key_idea(Z, DK);

        /*
        ** Allocate memory for buffers.  We'll make 3, called plain1,
        ** crypt1, and plain2.  It works like this:
        **   plain1 >>encrypt>> crypt1 >>decrypt>> plain2.
        ** So, plain1 and plain2 should match.
        ** Also, fill up plain1 with sample text.
        */
        plain1 = new byte[this.arraysize];
        crypt1 = new byte[this.arraysize];
        plain2 = new byte[this.arraysize];

        /*
        ** Note that we build the "plaintext" by simply loading
        ** the array up with random numbers.
        */
        for (i = 0; i < this.arraysize; i++)
        {
            plain1[i] = (byte)(ByteMark.abs_randwc(255) & 0xFF);
        }

        /*
        ** See if we need to perform self adjustment loop.
        */
        if (this.adjust == 0)
        {
            /*
            ** Do self-adjustment.  This involves initializing the
            ** # of loops and increasing the loop count until we
            ** get a number of loops that we can use.
            */
            for (this.loops = 100;
                 this.loops < global.MAXIDEALOOPS;
                 this.loops += 10)
            {
                if (DoIDEAIteration(plain1, crypt1, plain2,
                                    this.arraysize,
                                    this.loops,
                                    Z, DK) > global.min_ticks)
                {
                    break;
                }
            }
        }

        /*
        ** All's well if we get here.  Do the test.
        */
        accumtime  = 0;
        iterations = (double)0.0;

        do
        {
            accumtime += DoIDEAIteration(plain1, crypt1, plain2,
                                         this.arraysize,
                                         this.loops, Z, DK);
            iterations += (double)this.loops;
        } while (ByteMark.TicksToSecs(accumtime) < this.request_secs);

        /*
        ** Clean up, calculate results, and go home.  Be sure to
        ** show that we don't have to rerun adjustment code.
        */

        if (this.adjust == 0)
        {
            this.adjust = 1;
        }

        return(iterations / ByteMark.TicksToFracSecs(accumtime));
    }