Software Archive
Read-only legacy content
17061 Discussions

boost::thread and Amplifier

Brian_Hart
Beginner
222 Views
I've searched this forum and found some older posts about support in Parallel Studio for profiling boost::threads. We currently have a thread pool implementation built on top of boost::thread (boost version 1.39). When I run the Hot Spot version of Amplifier, it doesn't even show the worker threads in the thread filter, nor does it show any of the code that was run in the worker threads.
The earlier posts indicated that Parallel Studio possibly doesn't support the primitives on which boost::threads are built. Can someone clarify that for me and let me know whether that support will be coming soon, possibly even in Parallel Studio 2011? I would like to be able to profile this code and would rather not have to port it to another threading library right now.
Thanks.
0 Kudos
1 Reply
Peter_W_Intel
Employee
222 Views

Hi,

Asa simple answer - not supported yet!

VTune Amplifier XE Beta supports (detects) APIs from traditional threading APIs, Intel TBB, OpenMP* and Intel Cilk - Boost is not included!
However some of the boost thread apis map back to standard posix thread apis. VTune Amplifier XE should capture thread creation and concurrency correctly.

I ever used Boost v1.37 on Linux* to build a small program, which createdtwo new threadsto do writing into buffer and reading from buffer.

#include
#include
#include
#include

const int BUF_SIZE = 100;
const int ITERS = 10000;

boost::mutex io_mutex;

class buffer
{
public:
typedef boost::mutex::scoped_lock scoped_lock;

buffer() : p(0), c(0), full(0) { }

void put(int m)
{
scoped_lock lock(mutex);
if (full == BUF_SIZE)
{
{

boost::mutex::scoped_lock lock(io_mutex);
std::cout << "Buffer is full. Waiting..." << std::endl;
}
while (full == BUF_SIZE)
cond.wait(lock);
}
buf

= m;
p = (p+1) % BUF_SIZE;
++full;
cond.notify_one();
}

int get()
{
scoped_lock lk(mutex);
if (full == 0)
{
{
boost::mutex::scoped_lock lock(io_mutex);
std::cout << "Buffer is empty. Waiting..." << std::endl;
}
while (full == 0)
cond.wait(lk);

}
int i = buf;
c = (c+1) % BUF_SIZE;
--full;
cond.notify_one();
return i;
}

private:
boost::mutex mutex;
boost::condition cond;
unsigned int p, c, full;
int buf[BUF_SIZE];
};

buffer buf;

void writer()
{
for (int n = 0; n < ITERS; ++n)
{
{
boost::mutex::scoped_lock lock(io_mutex);

std::cout << "sending: " << n << std::endl;
}
buf.put(n);
}
}

void reader()
{
for (int x = 0; x < ITERS; ++x)
{
int n = buf.get();
{
boost::mutex::scoped_lock lock(io_mutex);
std::cout << "received: " << n << std::endl;
}
}
}

int main(int argc, char* argv[])
{
boost::thread thrd1(&reader);
boost::thread thrd2(&writer);
thrd1.join();
thrd2.join();
return 0;
}


1) Hotspots - sometime result didn't show helpful info(Function name will be displayed as "[Unkown]") - if you run program shortly. That is why I put "ITERS" value to"10000"


2) Concurrency - result showthree threads in timeline report and function name can be displayed. Also all thread's activities can be captured, including thread creation, thread termination, thread transitions, Concurrency, CPU usage, etc.


3) Locks and Waits - result should show all sync-objects. We don't expect to get all the locks and waits done correctly, butsomemutexof BOOST still can bedetected!


Regards, Peter

0 Kudos
Reply