class MyThread : public HPCxx_Thread {
HPCxx_Collective<int> &coll;
int *infoAr, *newAr;
int totalThreads, myId, count, myCollectKey;
public:
MyThread(int n, int id, HPCxx_Collective<int> &_coll):
totalThreads(n), myId(id), coll(_coll), HPCxx_Thread()
{
myCollectKey=coll.acquireKey();
}
void run() {
int size=10;
int total=0;
infoAr=new int[10];
srand48((int)infoAr);
cout << "Thread " << myId << " generating array values..." << endl;
for(count=0; count<10; count++) {
infoAr[count]=(int)(1000*drand48());
}
cout << "Thread " << myId << " passing to collection..." << endl;
newAr=coll.gather(myCollectKey, infoAr, size);
for(count=0; count<totalThreads*10+1; count++) {
if(myId==0) {
cout << "newAr[" << count << "] = " << newAr[count] << endl;
}
total+=newAr[count];
}
cout << "Thread " << myId << "computed sum " << total << " Size returned was " << size << endl;
}
};
int foo(int n, HPCxx_Barrier barrier, HPCxx_Collective<int> coll){
MyThread *t[100];
int total=0, count=0, collectKey0;
int dummy=0;
int size=1, *infoAr;
for(int i = 0; i < n; i++){
t[i] = new MyThread(n, i, coll);
t[i]->start();
}
cout << "DONE" << endl << flush;
return 0;
}
int main(int argc, char **argv)
{
HPCxx_Group *g;
int n;
hpcxx_init(argc, argv, g);
cout << "INPUT" << endl << flush;
cout << "Number of threads : " << endl << flush;
cin >> n;
g->setNumThreads(n);
HPCxx_Barrier barrier(*g);
HPCxx_Collective<int> coll(g);
foo(n, barrier, coll);
return hpcxx_exit(g);
}
Last modified: Thu Apr 22 02:11:12 EST 1999