Click to See Complete Forum and Search --> : Parallel Processing


piyushnewe
May 16th, 2006, 04:16 AM
Hi,

I have one function which is doing various operations on String. These operations take almost 0.5 to 1 min to finish. I want to do these operations in parallel/multithreaded. Here my purpose is to learn parallel processing and not the string operations in Pure "C".

Can somebody suggest me on this?

-Piyush

zerver
May 16th, 2006, 12:40 PM
It all depends on what you are doing to the string.

Many operations are difficult or even impossible to run in parallel.

Generally speaking, it must be possible to split the task in several
smaller tasks so that each one can be run on a separate processor.

Is your string BIG?

Would it be posslble to split the string in half
and let two processors work on one half each?

piyushnewe
May 17th, 2006, 06:20 AM
Nope, my string is not so big.



Would it be posslble to split the string in half
and let two processors work on one half each?

But how to achieve this if i take big string?? Any clues?

-Piyush

zerver
May 17th, 2006, 09:46 AM
If you want me to be specific, you must describe your problem in more detail.

Or I can give you a generic example in pseudocode:

Suppose that I have a huge string and want to replace all occurrences of letter "A" with "B". To do this on two processors, I split the string in half.

const char s[]="ABASSADSDASDSASDSAAABBDSFDSJFLJDSFJSDLJLJDSF......
int slen=strlen(s);

const char *s1=s; // part 1
const char *s2=s+slen/2; // part 2

Start_Thread_On_Processor1(s1,slen/2); // 2nd arg here is string length

Start_Thread_On_Processor2(s2,slen-slen/2);

Wait_For_Results(); // wait until threads are finished

// return value is now in string s

sirikrishnap
May 22nd, 2006, 06:53 AM
Parallel processing as mentioned would only increase the time spent due to context switch, added conditions etc. Doing your operation in backgroud thread is sensible approach.

piyushnewe
May 22nd, 2006, 06:56 AM
Thanks for all your Inputs.

-Piyush

zerver
May 22nd, 2006, 09:42 AM
Parallel processing as mentioned would only increase the time spent due to context switch, added conditions etc. Doing your operation in backgroud thread is sensible approach.

Possibly, but on a PC with 2 or more processors there might be a speed gain even for simple things like string operations.

Regards / Z

Andreas Masur
May 22nd, 2006, 09:45 AM
Parallel processing as mentioned would only increase the time spent due to context switch, added conditions etc. Doing your operation in backgroud thread is sensible approach.
Well....actually involving a thread would also involve context switching... ;)

piyushnewe
May 23rd, 2006, 12:10 AM
Any good article on Parallel Processing for beginners ? I have went through the web but not get any beginners' doc.

-Piyush

Andreas Masur
May 24th, 2006, 02:23 PM
Introduction to Parallel Computing (http://www.llnl.gov/computing/tutorials/parallel_comp/)...

piyushnewe
May 24th, 2006, 11:47 PM
Thanks Everyone.
Andreas Masur ,
This is very good article. Thanks for that.

-Piyush