Last active
January 22, 2025 20:11
-
-
Save dkurt/00e0601779bad4e31dc8f5587f376262 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Diagnostics; | |
float[,] image = new float[10000, 10000]; | |
var rng = new Random(); | |
for (int i = 0; i < image.GetLength(0); i += 1) | |
{ | |
for (int j = 0; j < image.GetLength(1); j += 1) | |
{ | |
image[i, j] = ((float)rng.Next()) / Int32.MaxValue; | |
} | |
} | |
float[,] accum = new float[image.GetLength(0) - 2, image.GetLength(1) - 2]; | |
Stopwatch timer = new Stopwatch(); | |
timer.Start(); | |
// for (int i = 0; i < accum.GetLength(0); i += 1) | |
// { | |
// for (int j = 0; j < accum.GetLength(1); j += 1) | |
// { | |
// accum[i, j] = 1; | |
// for (int k1 = 0; k1 < 3; k1 += 1) | |
// { | |
// for (int k2 = 0; k2 < 3; k2 += 1) | |
// { | |
// accum[i, j] += (float)Math.Exp(image[i + k1, j + k2]); | |
// } | |
// } | |
// } | |
// } | |
ParallelOptions options = new ParallelOptions(); | |
options.MaxDegreeOfParallelism = 2; | |
Parallel.For(0, accum.GetLength(0), options, (i, state) => | |
{ | |
for (int j = 0; j < accum.GetLength(1); j += 1) | |
{ | |
accum[i, j] = 1; | |
for (int k1 = 0; k1 < 3; k1 += 1) | |
{ | |
for (int k2 = 0; k2 < 3; k2 += 1) | |
{ | |
accum[i, j] += (float)Math.Exp(image[i + k1, j + k2]); | |
} | |
} | |
} | |
}); | |
timer.Stop(); | |
Console.WriteLine(timer.Elapsed); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment