public static ProcResult UpdateH(int steps, float qRate, float filpEnergy, float beta) { var strRet = String.Empty; _stopwatch.Reset(); _stopwatch.Start(); for (var s = 0; s < steps; s++) { var res9 = new int[_area]; strRet = strRet + _cudaArray.CopyIntsFromDevice(res9, d_flipData, _area); var bbs = FloatFuncs.Betas(_tempSteps, beta); strRet = strRet + _cudaArray.CopyFloatsToDevice(bbs, d_threshes, _allTempSteps); strRet = strRet + _randoProcs.MakeRandomInts(d_indexRands, _blockCount); strRet = strRet + _randoProcs.MakeUniformRands(d_flipRands, _blockCount); strRet = strRet + _gridProcs.Run_k_ThermoIsing_bp( temp_data: d_tempData, flip_data: d_flipData, index_rands: d_indexRands, flip_rands: d_flipRands, threshes: d_threshes, flip_energy: filpEnergy, block_size: _block_size, blocks_per_span: _blocks_per_span, q_rate: qRate); } _stopwatch.Stop(); var dRet = new Dictionary <string, object>(); float[] bhts = new float[_area / 1024]; strRet = strRet + _cudaArray.RunBlockAddFloats_32_Kernel( destPtr: d_heatBlocks, srcPtr: d_tempData, span: _span ); strRet = strRet + _cudaArray.CopyFloatsFromDevice(bhts, d_heatBlocks, _area / 1024); float tot = bhts.Sum(); tot /= _area; dRet["TotalHeat"] = tot; var tres = new float[_area]; strRet = strRet + _cudaArray.CopyFloatsFromDevice(tres, d_tempData, _area); dRet["ThermGrid"] = new SimGrid <float>(name: "Therms", width: _span, height: _span, data: tres); var fres = new int[_area]; strRet = strRet + _cudaArray.CopyIntsFromDevice(fres, d_flipData, _area); dRet["FlipGrid"] = new SimGrid <int>(name: "Flips", width: _span, height: _span, data: fres); return(new ProcResult(data: dRet, err: strRet, stepsCompleted: steps, time: _stopwatch.ElapsedMilliseconds)); }
public static ProcResult UpdateE(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[10]; //thresh[1] = 1.0f; //thresh[3] = 1.0f; thresh[1] = 1.0f - t4; thresh[3] = 1.0f - t2; thresh[5] = 0.5f; thresh[7] = t2; thresh[9] = t4; strRet = strRet + _cudaArray.CopyFloatsToDevice(thresh, d_betas, 10); IntPtr dSrc; IntPtr dDest = IntPtr.Zero; _stopwatch.Reset(); _stopwatch.Start(); float energyTot = 0; int[] resB = new int[_area / 1024]; for (var s = 0; s < steps; s++) { if (_phase == 0) { dSrc = d_gridA; dDest = d_gridB; strRet = strRet + _randoProcs.MakeUniformRands(d_rands, _area); _phase = 1; } else { dSrc = d_gridB; dDest = d_gridA; _phase = 0; } strRet = strRet + _gridProcs.Runk_Ising_dg( destPtr: dDest, energyPtr: d_energy, srcPtr: dSrc, randPtr: d_rands, span: _span, alt: _phase, threshPtr: d_betas ); strRet = strRet + _cudaArray.RunBlockAddInts_32_Kernel( destPtr: d_energyBlocks, srcPtr: d_energy, span: _span ); strRet = strRet + _cudaArray.CopyIntsFromDevice(resB, d_energyBlocks, _area / 1024); energyTot += (float)resB.Sum() / (float)_area; } energyTot /= steps; int[] res = new int[_area]; strRet = strRet + _cudaArray.CopyIntsFromDevice(res, dDest, _area); _stopwatch.Stop(); var dRet = new Dictionary <string, object>(); dRet["Grid"] = new SimGrid <int>(name: "UpdateE", width: _span, height: _span, data: res); dRet["Energy"] = energyTot; return(new ProcResult(data: dRet, err: strRet, stepsCompleted: steps, time: _stopwatch.ElapsedMilliseconds)); }
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)); }