arrays - Multiplying a matrix by a vector of scalars in parallel C# -


i have 2 dictionaries of arrays multiplied , stored in dictionary of strings , int[]. code works

public class program {     public static void main(string[] args)     {         int[] = {1,0,3,4,0};         int[] b = { 3, 0, 9, 10, 0};         int[] c = {2,3,3,5,0};         var ret = new dictionary<string, int[]>();         ret.add("jack", a);         ret.add("jane", b);         ret.add("james", c);          var multipliers = new dictionary<string, int>();         multipliers.add("jack", 2);         multipliers.add("jane", 3);         multipliers.add("james", 5);          var results = new dictionary<string, int[]>();          foreach (var item in ret)         {             int[] arr= new int[item.value.length];              (int = 0; < item.value.length; ++)             {                 int d = item.value[i] * multipliers[item.key];                  arr[i] = d;             }             results.add(item.key,arr);         }     } } 

what efficient way this? there way in parallel?

the following code snippet way in parallel:

var results = new concurrentdictionary<string, int[]>();  parallel.foreach(ret, pair => {       var srcarr = pair.value;       var arr = new int[srcarr.length];       var multby = multipliers[pair.key];        (var = 0; < srcarr.length; i++)       {            var d = srcarr[i] * multby;             arr[i] = d;       }       results[pair.key] = arr; }); 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -