Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am trying to parallelize a large program that is written by a third-party. I cannot disclose the code, but I will try and give the closest example of what I wish to do.
Based on the code below. As you can see, since the clause "parallel" is INSIDE the while loop, the creation/destruction of the threads are(is) done with each iteration, which is costly.
Given that I cannot move the Initializors...etc to be outside the "while" loop.

--Base code
void funcPiece0()
{
	// many lines and branches of code
}


void funcPiece1()
{
	// also many lines and branches of code
}

void funcCore()
{
	funcInitThis();
	funcInitThat();

#pragma omp parallel
	{
#pragma omp sections
		{
#pragma omp section
			{
				funcPiece0();
			}//omp section
#pragma omp section
			{
				funcPiece1();
			}//omp section
		}//omp sections
	}//omp parallel

}

int main()
{

	funcInitThis();
	funcInitThat();
#pragma omp parallel
    {
	while(1)
	{
		funcCore();
	}
    }

}

What I seek to do is to avoid the creation/destruction per-iteration, and make it once at the start/end of the program. I tried many variations to the displacement of the "parallel" clause. What I basically has the same essence is the below: (ONLY ONE thread creation/destruction per-program run)
--What I tried, but failed "illegal access" in the initializing functions.
void funcPiece0()
{
	// many lines and branches of code
}


void funcPiece1()
{
	// also many lines and branches of code
}

void funcCore()
{
	funcInitThis();
	funcInitThat();

//#pragma omp parallel
//	{
#pragma omp sections
		{
#pragma omp section
			{
				funcPiece0();
			}//omp section
#pragma omp section
			{
				funcPiece1();
			}//omp section
		}//omp sections
//	}//omp parallel

}

int main()
{

	funcInitThis();
	funcInitThat();

	while(1)
	{
		funcCore();
	}

}

--

Any help would be highly appreciated!
Thanks!

p.s. I see no tag for OpenMP...?
Posted

1 solution

OpenMP can't be used the way you want. You need to remove the OpenMP directives and create the threads by yourself using boost::thread or OS-specific APIs.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900