Václav Šmilauer said: (by the date of Thu, 29 Apr 2010 21:18:01 +0200)
> That is quite possible. I also had best results with 5 cores on > Opterons, but Xeons were getting faster up to 8 cores (about 5.5x). > Depends on memory bus and other stuff I don't understand that much. > > The jumping speed could be also explained bu the GUI thread blocked by > computation, so it updates only very rarely and shown nonsense values. > > Note that there are still some global locks (such as when creating > interaction) and non-parallel parts like the collider. > > See https://www.yade-dem.org/wiki/Triaxial_Test_Parallel and > https://www.yade-dem.org/wiki/Performance_Tuning, in most cases 3-4 > cores give the best performance. I see, how about using this one, to avoid global locking: http://www.chaoticmind.net/~hcb/projects/boost.atomic/ It seems however that currently only fundamental types are supported. I asked the author about that. If you remove 'Something' from attached test file, it will work nicely. -- Janek Kozicki http://janek.kozicki.pl/ |
#include<iostream>
#include<boost/thread.hpp>
#include<boost/bind.hpp>
#include<boost/atomic.hpp>
#include<vector>
class Something
{
private:
int val;
public:
Something(){};
Something(int i):val(i){};
void set_val(int i) {val=i;};
int get_val() {return val;};
};
class Numbers
{
public:
boost::atomic<int> sum,t1,t2;
Numbers():sum(0),t1(0),t2(0){};
};
class Thread1
{
public:
void run(Numbers& c)
{
int i(100000);
while(i-->0)
++c.sum,c.t1++;
}
};
class Thread2
{
public:
void run(Numbers& c)
{
int i(100000);
while(i-->0)
c.sum++,c.t2++;
}
};
class Display
{
public:
void run(Numbers& n)
{
int i(103);
while(i-->0)
{
int sum(n.sum);
int t1(n.t1);
int t2(n.t2);
int SUM(t1+t2);
std::cout << n.sum << " " << n.t1 << " " << n.t2 << " .. " << SUM << " " << (int)(SUM==sum) << "\n";
}
}
};
int main(int argc, char** argv)
{
Numbers num;
std::vector<boost::atomic<Something> > v;
v.resize(100);
Thread1 t1;
Thread2 t2;
Display disp;
boost::thread_group run;
run.create_thread(boost::bind(&Thread1::run,boost::ref(t1), boost::ref(num)));
run.create_thread(boost::bind(&Thread2::run,boost::ref(t2), boost::ref(num)));
run.create_thread(boost::bind(&Display::run,boost::ref(disp),boost::ref(num)));
run.join_all();
}
makefile
Description: Binary data
_______________________________________________ Mailing list: https://launchpad.net/~yade-dev Post to : [email protected] Unsubscribe : https://launchpad.net/~yade-dev More help : https://help.launchpad.net/ListHelp

