Hi Guys,

I am trying to do design a coarse grain algorithm in MPI for carrying out multiple pattern searches. For which I have created a function that does the main pattern searches as shown in the algorithm below called hostMatch. The code below, reads in the data and sends it to processes. But the results I get are never right, by what I mean is it either returns too many pattern searches or too less. Its intermitting :(

FILE *out;
	char fileName[1000];
#ifdef DOS
	sprintf (fileName, "result_%d.txt",rank);
#else
	sprintf (fileName, "result_%d.txt",rank);
#endif
	out = fopen( fileName, "w+");
	if (out == NULL)
		return 0;

	while ( readTextData(textNumber) ) {
	
		if (readPatternData(rank)) {
			patternNumber = rank;
				hostMatch(out, textNumber, patternNumber, control, appearances );	 
		}
		textNumber++;
	} 
	MPI_Barrier(MPI_COMM_WORLD);
	MPI_Finalize();
	fclose(out);

Here is the process file I created which shows how each processor handles the data:

---------------------------
Process 0: Pattern 0 Text 0
Process 0: Pattern 0 Text 1
Process 0: Pattern 0 Text 2
Process 0: Pattern 0 Text 3
Process 0: Pattern 0 Text 4
---------------------------
Process 1: Pattern 0 Text 0
Process 1: Pattern 1 Text 1
Process 1: Pattern 1 Text 2
Process 1: Pattern 1 Text 3
Process 1: Pattern 1 Text 4
---------------------------
Process 2: Pattern 0 Text 0
Process 2: Pattern 2 Text 1
Process 2: Pattern 2 Text 2
Process 2: Pattern 2 Text 3
Process 2: Pattern 2 Text 4
---------------------------
Process 3: Pattern 0 Text 0
Process 3: Pattern 3 Text 1
Process 3: Pattern 3 Text 2
Process 3: Pattern 3 Text 3
Process 3: Pattern 3 Text 4
---------------------------
Process 4: Pattern 0 Text 0
Process 4: Pattern 4 Text 1
Process 4: Pattern 4 Text 2
Process 4: Pattern 4 Text 3
Process 4: Pattern 4 Text 4
---------------------------
Process 5: Pattern 0 Text 0
Process 5: Pattern 5 Text 1
Process 5: Pattern 5 Text 2
Process 5: Pattern 5 Text 3
Process 5: Pattern 5 Text 4

Any suggestions?

Recommended Answers

All 5 Replies

Where are the printf statements in the code snippet that you have posted ?
What does read Pattern data do ?

Where are the printf statements in the code snippet that you have posted ?
What does read Pattern data do ?

Hi, Read pattern data, read in the number of pattern files from a folder which is compared to the text files to find a pattern.

THe printf, prints the number of patterns found.

The problem in code is the distribution of pattern and text to each processess which I think I am doing wrong. I think the master needs to read in data and distribute it to each processes.

I wanted to add, in the above while loop it is loading and processing the data using 10 processes so basically if I have 10 pattern files then it load 10 but the problem is what if there is 20? Both pattern+texts have to be loaded into 16 given processors.

Does the load on each process have to be the same ? One solution could be to give one job to each process and a distribute the other 4 jobs to random 4 processes ...

Does the load on each process have to be the same ? One solution could be to give one job to each process and a distribute the other 4 jobs to random 4 processes ...

My whole approach was wrong. The code above is actually a normal serial program and in no represents MPI :)

So I went back to basics and applied proper MPI functions like ISend, BCast, IRecv etc

In the end it all worked out.

Thanks for your time and help :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.