knowledge-database (beta)

Current group: comp.benchmarks

memory bandwidth tester

memory bandwidth tester  
John
 Re: memory bandwidth tester  
John
From:John
Subject:memory bandwidth tester
Date:23 Jan 2005 13:50:40 -0800


Does anyone have a small code based on pthreads that
can measure the bandwidth from memory to CPU on my 4
processor 64-bit xeon system. I somehow think its very
slow. Or any pointers where I could pick such a test?

Thanks,
--j
From:John
Subject:Re: memory bandwidth tester
Date:23 Jan 2005 17:06:47 -0800
I wrote a small tester to test the latency of a shared memory system.
Anyone has any comments on it?

For now the number of threads can be controlled.
And what it does is just accesses random memory locations
and increments them. The total number of accesses a cpu can
do per second can be calcuated by cout << "Number of integers = " <<
mod_size << endl; divided by time taken.

Any comments/suggestions/criticims/... ?

Thanks,
--j




// g++ bench.cpp -O3 -lpthread -o bench -lm

#include
#include
#include "timer.hpp"
#include

using namespace std;


const unsigned long long mod_size = 512*1024*1024 / 8; // Replace the
first number with Megabytes you want to test with.
const int nthreads = 2;

struct thread_data{
unsigned long long _begin,_end;
unsigned long long *harray;
int tid;
};

struct thread_data thread_data_array[nthreads];
pthread_t threads[nthreads];



void *smemfill(void *threadarg)
{
struct thread_data *my_data;
my_data = (struct thread_data *) threadarg;
cout << "Thread : (" << my_data->_begin << ", " <<
my_data->_end<< ")"<< endl;
cout.flush();

for(unsigned long long j = my_data->_begin;
j < my_data->_end; ++j){
my_data->harray[my_data->harray[j]]++;
// cout << "Index " << my_data->harray[j] << " updated by
Thread " << my_data->tid << endl;
cout.flush();
}


pthread_exit((void *) 0);
}



int main(int argc, char** argv){

cout << "Size of long long = " << sizeof(long long) << endl;
cout << "rand() max = " << RAND_MAX << endl;
cout << "Number of integers = " << mod_size << endl;
unsigned long long *harray = new unsigned long long[mod_size];
MyTimer_display td(mod_size);
for(unsigned long long j = 0; j < mod_size; ++j){
harray[j] = rand() % mod_size;
++td;
}

MyTimer totime;
int rc,status;
for(int i = 0; i < nthreads;++i){
thread_data_array[i]._begin = i*mod_size/nthreads;
thread_data_array[i]._end = ((i+1)*mod_size/nthreads)-1;
thread_data_array[i].harray = harray;
thread_data_array[i].tid = i;
rc = pthread_create(&threads[i], NULL, smemfill,
(void *) &thread_data_array[i]);
if (rc){
cerr << "ERROR; return code from pthread_join() is"
<< rc << endl;
exit(-1);
}
}


for(int t=0;t < nthreads;t++)
{
cout << "Waiting...\n";
rc = pthread_join(threads[t], (void **)&status);
if (rc)
{
cerr << "ERROR; return code from pthread_join() is"
<< rc << endl;
exit(-1);
}
printf("Completed join with thread %d status= %d\n",t, status);
}


cout <<"Total time = " << totime << endl;
delete[] harray;

pthread_exit(NULL);
return 0;
}
   

Copyright © 2006 knowledge-database   -   All rights reserved