Click here to Skip to main content
15,885,032 members
Home / Discussions / C#
   

C#

 
QuestionWindows Identity of the currently logged in user Pin
ramz_g20-Oct-09 22:23
ramz_g20-Oct-09 22:23 
AnswerRe: Windows Identity of the currently logged in user Pin
stancrm20-Oct-09 22:31
stancrm20-Oct-09 22:31 
GeneralRe: Windows Identity of the currently logged in user Pin
ramz_g20-Oct-09 23:11
ramz_g20-Oct-09 23:11 
AnswerRe: Windows Identity of the currently logged in user Pin
Eddy Vluggen20-Oct-09 23:40
professionalEddy Vluggen20-Oct-09 23:40 
GeneralRe: Windows Identity of the currently logged in user Pin
ramz_g21-Oct-09 2:05
ramz_g21-Oct-09 2:05 
GeneralRe: Windows Identity of the currently logged in user Pin
Eddy Vluggen21-Oct-09 3:18
professionalEddy Vluggen21-Oct-09 3:18 
GeneralRe: Windows Identity of the currently logged in user Pin
ramz_g21-Oct-09 19:15
ramz_g21-Oct-09 19:15 
QuestionSafe Parallel loops Pin
tvbarnard20-Oct-09 21:49
tvbarnard20-Oct-09 21:49 
Good day

I've written code that is very computationally intensive, and therefore would like to use threads to parallel process the data (I've got a duo core pc)

The first solution I though of was to use "Parallel.For()" for the outer loop, but for some reason it corrupts my data.

This is the basic form of the code I want to parallelise:

List<int[,]> largeData; //a 5000x500 matrix
List<int[]> referenceList; //each int[] has about 10 elements
int answer;

//loops
foreach(int[] refArray in referenceList)
{
   foreach(int[,] largeMatrix in largeData)
   {
      answer = 0;

      foreach(int ref in refArray)
      {
         answer += largeMatrix[ref];         
      }
      
      //use "answer" for more processing here
   }
}


"Foreach" might not be the optimal choice for the loops, but I used it here to make the example simpler to understand.

I have tried replacing the first (outer) loop with Parallel.For(...), but then my "answer" value changes, implying that the threads corrupt the answer.

If you could help me with a "safe" approach of computing this in parallel I would greatly appreciate it, since figuring this out with almost no knowledge on threads is a daunting task.

tvb

AnswerRe: Safe Parallel loops Pin
stancrm20-Oct-09 22:27
stancrm20-Oct-09 22:27 
GeneralRe: Safe Parallel loops Pin
tvbarnard20-Oct-09 22:44
tvbarnard20-Oct-09 22:44 
GeneralRe: Safe Parallel loops Pin
stancrm20-Oct-09 22:55
stancrm20-Oct-09 22:55 
GeneralRe: Safe Parallel loops Pin
tvbarnard20-Oct-09 23:06
tvbarnard20-Oct-09 23:06 
AnswerRe: Safe Parallel loops [modified] Pin
Hristo-Bojilov20-Oct-09 22:38
Hristo-Bojilov20-Oct-09 22:38 
GeneralRe: Safe Parallel loops Pin
tvbarnard20-Oct-09 22:45
tvbarnard20-Oct-09 22:45 
GeneralRe: Safe Parallel loops Pin
Hristo-Bojilov20-Oct-09 23:55
Hristo-Bojilov20-Oct-09 23:55 
GeneralRe: Safe Parallel loops Pin
tvbarnard20-Oct-09 22:47
tvbarnard20-Oct-09 22:47 
GeneralRe: Safe Parallel loops Pin
tvbarnard20-Oct-09 22:58
tvbarnard20-Oct-09 22:58 
GeneralRe: Safe Parallel loops Pin
Luc Pattyn21-Oct-09 2:47
sitebuilderLuc Pattyn21-Oct-09 2:47 
GeneralRe: Safe Parallel loops Pin
tvbarnard21-Oct-09 3:06
tvbarnard21-Oct-09 3:06 
QuestionEmbed image to an e-mail and not a link… Pin
anderslundsgard20-Oct-09 21:27
anderslundsgard20-Oct-09 21:27 
AnswerRe: Embed image to an e-mail and not a link… Pin
Christian Graus20-Oct-09 21:42
protectorChristian Graus20-Oct-09 21:42 
AnswerRe: Embed image to an e-mail and not a link… Pin
Giorgi Dalakishvili20-Oct-09 23:36
mentorGiorgi Dalakishvili20-Oct-09 23:36 
QuestionProblem in accessing the COM port. "Access denied for COM1 " Pin
pallaka20-Oct-09 21:09
pallaka20-Oct-09 21:09 
AnswerRe: Problem in accessing the COM port. "Access denied for COM1 " Pin
stancrm20-Oct-09 21:24
stancrm20-Oct-09 21:24 
GeneralRe: Problem in accessing the COM port. "Access denied for COM1 " Pin
pallaka20-Oct-09 21:46
pallaka20-Oct-09 21:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.