Ejemplo n.º 1
0
        public static ProcResult GetEnergy()
        {
            var strRet = String.Empty;

            int[] res = new int[_area / 1024];

            strRet = strRet + _cudaArray.RunBlockAddInts_32_Kernel(
                destPtr: d_energyBlocks,
                srcPtr: d_energy,
                span: _span
                );

            strRet = strRet + _cudaArray.CopyIntsFromDevice(res, d_energyBlocks, _area / 1024);

            float tot = res.Sum();

            tot /= _area;

            var dRet = new Dictionary <string, object>();

            dRet["Grid"]   = res;
            dRet["Energy"] = tot;
            return(new ProcResult(data: dRet,
                                  err: strRet,
                                  stepsCompleted: 0,
                                  time: _stopwatch.ElapsedMilliseconds));
        }
Ejemplo n.º 2
0
        public static ProcResult ProcIsingRb(int steps, float temp)
        {
            var strRet = String.Empty;

            float t2 = (float)(1.0 / (1.0 + Math.Exp(2 * temp)));
            float t4 = (float)(1.0 / (1.0 + Math.Exp(4 * temp)));

            float[] thresh = new float[5];
            //thresh[0] = 1.0f;
            //thresh[1] = 1.0f;
            thresh[0] = 1.0f - t4;
            thresh[1] = 1.0f - t2;
            thresh[2] = 0.5f;
            thresh[3] = t2;
            thresh[4] = t4;

            strRet = strRet + _cudaArray.CopyFloatsToDevice(thresh, d_betas, 5);

            _stopwatch.Reset();
            _stopwatch.Start();

            for (var i = 0; i < steps; i++)
            {
                strRet = strRet + _randoProcs.MakeRandomInts(d_indexRands, _blockCount);
                strRet = strRet + _randoProcs.MakeUniformRands(d_tempRands, _blockCount);

                strRet = strRet + _gridProcs.Run_k_Ising_bp(
                    destPtr: d_grid,
                    energyPtr: d_energy,
                    indexRandPtr: d_indexRands,
                    tempRandPtr: d_tempRands,
                    block_size: _block_size,
                    blocks_per_span: _blocks_per_span,
                    threshPtr: d_betas
                    );
            }

            strRet = strRet + _gridProcs.Runk_Energy4(d_energy, d_grid, _span);

            int[] mres = new int[_area / 1024];

            strRet = strRet + _cudaArray.RunBlockAddInts_32_Kernel(
                destPtr: d_energyBlocks,
                srcPtr: d_energy,
                span: _span);

            strRet = strRet + _cudaArray.CopyIntsFromDevice(mres, d_energyBlocks, _area / 1024);

            float tot = mres.Sum();

            tot /= _area;


            int[] res = new int[_area];
            strRet = strRet + _cudaArray.CopyIntsFromDevice(res, d_grid, _area);

            _stopwatch.Stop();


            //uint[] res2 = new uint[_blockCount];
            //strRet = strRet + _cudaArray.CopyUIntsFromDevice(res2, d_rands, _blockCount);

            var dRet = new Dictionary <string, object>();

            dRet["Grid"] = new SimGrid <int>(name: "Update",
                                             width: _span,
                                             height: _span,
                                             data: res);

            dRet["Energy"] = tot;

            return(new ProcResult(data: dRet,
                                  err: strRet,
                                  stepsCompleted: steps,
                                  time: _stopwatch.ElapsedMilliseconds));
        }