VC++ 2010 エクスプレス インストールの期限が切れたので、日付を右下から変更しないと使用できません。私はこれをしたくないので、これらの質問をします:
マルチスレッドプログラムの下のスレッドは順番に動いていると思いますか?
次の 1000 個の粒子を計算するために同様のスレッドを 3 つ追加するとどうなりますか?
注: 各計算 (force、vel.、pos. の各計算) には約 9 ms かかります。
Something like this:
core1:first 1000 particles forces //
core2:first 1000 particles velocities //===>these 3 are connected
core3:first 1000 particles positions // ------------------------------
|
core4:next 1000 particles forces // ====these 2 will be connected
core5:next 1000 particles velocities //===>these 3 are connected |
core6:next 1000 particles positions // ------------------------------
boolean locker1;
boolean locker2;
boolean locker3;
boolean worker1;
boolean worker2;
boolean worker3;
void core1(void * x)
{
while(worker1)
{
while(!locker1){Sleep(10);}
for(int i=0;i<1000;i++)
{
//calculate 1000 particles forces
}
locker2=true; //starts core2 thread
while(locker2){Sleep(10);} //core2 must be working
while(locker3){Sleep(10);} //core3 must be working
}
_endthread();
}
void core2(void * y)
{
while(worker2)
{
if(!locker2){Sleep(10);}
for(int i=0;i<1000;i++)
{
//calculate 1000 particles velocities
}
locker3=true; //starts core3 thread
while(locker3){Sleep(10);} //core3 must be working
while(locker1){Sleep(10);} //core1 must be working
}
_endthread();
}
void core3(void * z)
{
while(worker3)
{
if(!locker3){Sleep(10);}
for(int i=0;i<1000;i++)
{
//calculate 1000 particles positions
}
locker1=true; //starts core1 thread
while(locker1){Sleep(10);} //core1 must be working
while(locker2){Sleep(10);} //core2 must be working
}
_endthread();
}
int main()
{
locker1=false;
locker2=false;
locker3=false;
worker1=true;
worker2=true;
worker3=true;
_beginthread(core1,0,(void *)0);
_beginthread(core2,0,(void *)0);
_beginthread(core3,0,(void *)0);
locker1=true; //gets the waiting core1-thread working
//so i think when it finishes, it releases core2 to work
//when core2 finishes, core3 starts working
Sleep(100);
worker1=false;
worker2=false;
worker3=false; //after a while i shut them down
}
VC++ を使用している方がヒントや提案をいただければ幸いです。
Or should i just forget the 3+3-->2 system and do this(6)? :
core1 first 233 particles for computing forces ----->all for velocity ----->all for psoition
core2 next 233 particles for computing forces ----->all for velocity ----->all for psoition
core3 next 233 particles for computing forces ----->all for velocity ----->all for psoition
core4 next 233 particles for computing forces ----->all for velocity ----->all for psoition
core5 next 233 particles for computing forces ----->all for velocity ----->all for psoition
core6 last 233 particles for computing forces ----->all for velocity ----->all for psoition
and just wait all of them finish to get to next calculation?