954,480 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Help with Fork()

Could someone please advise me on how to implement fork() in a parallel processing (multiplying) of a 2d array....I have been at this for far too long..

here is my code

for (int i = 0; i < rowCol[0]; i++ ) result[i] = (float*)malloc ( rowCol[1] * sizeof(float) );
	int i = 0;
	int j = 0;
	int k = 0;
	
	for(i = 0; i < rowCol[0]; i++) 
	{
		for( j = 0; j <rowCol[3]; j++)
		{		
			result[i][j] = 0;
			for( k = 0; k < rowCol[1]; k++)
			{
				result[i][j] += (matrix1[i][k] * matrix2[k][j]);

			}
			
		}
	}


Any step in the right direction would be greatly appreciated

Thanks

PMACLEAN
Newbie Poster
4 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

Unless its a requirement I won't use fork in this situation...I would use threads..

gerard4143
Nearly a Posting Maven
2,272 posts since Jan 2008
Reputation Points: 512
Solved Threads: 387
 

H there, actually it is a requirement for this assignment....out of curiosity, how would you implement with threads...

PMACLEAN
Newbie Poster
4 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 
H there, actually it is a requirement for this assignment....out of curiosity, how would you implement with threads...

If your having problems with fork() then threads should probably wait. One question, how are you coordinating the calculating and passing of data between the two processes(parent and forked child)..

gerard4143
Nearly a Posting Maven
2,272 posts since Jan 2008
Reputation Points: 512
Solved Threads: 387
 

I am trying to use waitpid but not sure what exactly is going on.....

PMACLEAN
Newbie Poster
4 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

Here's a simple fork/pipe example that passes data from the child to the parent.

Note you'll have to scroll down a few pages to find it:

http://www.daniweb.com/forums/thread258136.html

This simple example has most of the elements that you'll need..

gerard4143
Nearly a Posting Maven
2,272 posts since Jan 2008
Reputation Points: 512
Solved Threads: 387
 

How many child processes do you have to create ?
In the sense, you create 1 child process, it does the computation and sends the result back
Or the more complicated scenario
Each child computes only 1 row of the result matrix and you have to create as many children as their are rows

abhimanipal
Master Poster
742 posts since Dec 2009
Reputation Points: 114
Solved Threads: 104
 

I believe the second scenario is what I am after

PMACLEAN
Newbie Poster
4 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

Hummm ...... Are you creating 10 children simultaneously ?

abhimanipal
Master Poster
742 posts since Dec 2009
Reputation Points: 114
Solved Threads: 104
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: