12-11-2008
Linux quad core Intel Xeon (2.99GHz, 16G memory)
compiler gcc version 4.1.2 20071124 (Red Hat 4.1.2-42)
I only use -lpthread
Code:
typedef struct{
int thread_no;
int allthread;
mat *G,*C,*B;
mat *us, *Z;
vec *samples;
double *Control, *Info;
} parm;
void sampleLU(int thread_no, int allthread, mat *G, mat *C, mat *B, mat &us, mat &Z, vec &samples, double Control[], double Info[])
{
Real_Timer lu_symbolic_init, lu_symbolic_free, lu_numerical, lu_solve_time;
Real_Timer sCpG_run_time;
int np = samples.size();
int nDim = B->m;
int start, stop;
start = thread_no * (int)(np/allthread);
stop = start + (int)(np/allthread) - 1;
if( thread_no == allthread-1 ) stop = np-1;
for (int i = start; i<=stop; i++ ){
cs *A;
if(thread_no == 0) {
sCpG_run_time.start();
A = G+sample(i)*C;
sCpG_run_time.stop();
}
else{
A = G+sample(i)*C;
}
/* LU decomposition */
...
if(i == start){
if(thread_no == 0) {
lu_symbolic_init.start();
A = LU;
lu_symbolic_init.stop();
}
else {
A = LU
}
}
/* solve Az = b */
double* z = new double[nDim];
vec b(nDim);
b.zeros();
if(thread_no == 0) lu_solve_time.start();
LUz=b
vec zz(z, nDim);
delete [] z;
Z.set_col(i, zz);
...
}
if(thread_no == 0){
std::cout << "Thread" << thread_no << " sC+G \t:" << sCpG_run_time.get_time() << std::endl;
std::cout << "Thread" << thread_no << " symbolic initial time: \t"<<lu_symbolic_init.get_time()<<std::endl;
std::cout << "Thread" << thread_no << " LU decomposition time \t:" << lu_numerical.get_time() << std::endl;
std::cout << "Thread" << thread_no << " symbolic free time: \t"<<lu_symbolic_init.get_time()<<std::endl;
std::cout << "Thread" << thread_no << " LU solve time \t: " << lu_solve_time.get_time() <<std::endl;
}
}
void * psampleLU(void *arg)
{
parm *p = (parm *)arg;
sampleLU(p->thread_no, p->allthread, p->G, p->C, p->B, *(p->us), *(p->Z), *(p->samples), p->Control, p->Info);
return NULL;
}
int main(int argc, char* argv[]){
pthread_t *threads;
pthread_attr_t pthread_custom_attr;
parm *arg;
threads = (pthread_t *)malloc(allthread * sizeof(pthread_t));
pthread_attr_init(&pthread_custom_attr);
arg = (parm *)malloc(allthread * sizeof(parm));
for ( int i=0; i<allthread; i++){
arg[i].thread_no = i;
arg[i].allthread = allthread;
arg[i].G = G;
arg[i].C = C;
arg[i].B = B;
arg[i].us = &us;
arg[i].Z = &Z;
arg[i].samples = &samples;
arg[i].Control = Control;
arg[i].Info = Info;
/*arg[i].dim = NDIM;
arg[i].a = &a;
arg[i].b = &b;
arg[i].c = &c;*/
if(i == 0) pthread_samplingLU.start();
pthread_create(&threads[i], &pthread_custom_attr, psampleLU,(void*)(arg+i));
//pthread_create(&threads[i], NULL, psampleLU,(void*)(arg+i));
}
for ( int i=0; i<allthread; i++){
pthread_join(threads[i], NULL);
if(i == 0) pthread_samplingLU.stop();
}
free(arg);
}
}
10 More Discussions You Might Find Interesting
1. Programming
Can someone point to a link where I can get good info about pthread?
thanx.. :) (1 Reply)
Discussion started by: jyotipg
1 Replies
2. Programming
consider if the thread routine returns any void pointer while calling pthread_join,
the thread resources are freed and the thread will be terminated when the main thread is exit ,that is my assumption whether it is true
how do we find whether the thread is alive or terminated
how do we find... (0 Replies)
Discussion started by: MKSRaja
0 Replies
3. Programming
hallo 2 al
can anyone pls tell me where and how can i find and install the pthread.h lib ?
thx :cool: (2 Replies)
Discussion started by: XinU*
2 Replies
4. Solaris
Hi all!
I am working on unix systems.I am programming in c.
I have got some problems with pthread.when I use pthread_create to creat a thread it says:
(.text+0x3a): undefined reference to `pthread_create'.
same is the problm with pthread_kill.
Can anyone help me out here.
Thanks.
vij. (2 Replies)
Discussion started by: vijlak
2 Replies
5. Programming
Hello all,
I'm working on a small wrapper library for a bigger project, and i've been killing my self over (what I think is) a pointer problem.
Here is the code (I extracted the part of the code where the problem is for better reading, I tested the code below, and I get the same problem):... (13 Replies)
Discussion started by: tmp0
13 Replies
6. Programming
Hello all.
I have made an application in C using pthreads. My problem is that my program seems to be only using 1 of my cores when I create multiple threads. I have 4 cores (Q9300). I am using Ubuntu 8.04.
I do believe the problem is that on linkage it's using a pthread emulation package... (4 Replies)
Discussion started by: LightRaven
4 Replies
7. Programming
Hi all,
How can i parallize this code in pthread?
for(round=1;round<=16;round++)
{
Expansion(mid, 17 - round - 1, left);
Expansion(mid, round - 1, right);
round++;
Expansion(right, 17 - round - 1, mid);
Expansion(left, round - 1,mid);
}
Whereby each loop depend on the... (2 Replies)
Discussion started by: m_enayah
2 Replies
8. UNIX for Advanced & Expert Users
I am so confused about the user threads and kernel threads.Suppose I created a thread using pthread create call in Linux ,whether it will be a user thread or kernel thread.If it user thread,then how its map to kernel thread.
I heard about the M:1,M:N,1:1 mapping methods.Which method linux is... (1 Reply)
Discussion started by: sujith4u87
1 Replies
9. Ubuntu
Hi all,
I wrote some code in c, using pthread (I configured the linker and compiler in eclipse IDE first).
#include <pthread.h>
#include "starter.h"
#include "UI.h"
Page* MM;
Page* Disk;
PCB* all_pcb_array;
void* display_prompt(void *id){
printf("Hello111\n");
return... (1 Reply)
Discussion started by: elad2109
1 Replies
10. Programming
I have a while loop like so:
while (counter (file1));
how can I pass that into a pthread_create()?
I was thinking ...
while(pthread_create(&path, NULL, counter, file));
is that right? (1 Reply)
Discussion started by: l flipboi l
1 Replies
LEARN ABOUT SUNOS
pthread.h
pthread.h(3HEAD) Headers pthread.h(3HEAD)
NAME
pthread.h, pthread - threads
SYNOPSIS
#include <pthread.h>
DESCRIPTION
The <pthread.h> header defines the following symbols:
PTHREAD_BARRIER_SERIAL_THREAD
PTHREAD_CANCEL_ASYNCHRONOUS
PTHREAD_CANCEL_ENABLE
PTHREAD_CANCEL_DEFERRED
PTHREAD_CANCEL_DISABLE
PTHREAD_CANCELED
PTHREAD_COND_INITIALIZER
PTHREAD_CREATE_DETACHED
PTHREAD_CREATE_JOINABLE
PTHREAD_EXPLICIT_SCHED
PTHREAD_INHERIT_SCHED
PTHREAD_MUTEX_DEFAULT
PTHREAD_MUTEX_ERRORCHECK
PTHREAD_MUTEX_INITIALIZER
PTHREAD_MUTEX_NORMAL
PTHREAD_MUTEX_RECURSIVE
PTHREAD_ONCE_INIT
PTHREAD_PRIO_INHERIT
PTHREAD_PRIO_NONE
PTHREAD_PRIO_PROTECT
PTHREAD_PROCESS_SHARED
PTHREAD_PROCESS_PRIVATE
PTHREAD_SCOPE_PROCESS
PTHREAD_SCOPE_SYSTEM
The types listed below are defined as described in <sys/types.h>. See types.h(3HEAD).
pthread_attr_t
pthread_barrier_t
pthread_barrierattr_t
pthread_cond_t
pthread_condattr_t
pthread_key_t
pthread_mutex_t
pthread_mutexattr_t
pthread_once_t
pthread_rwlock_t
pthread_rwlockattr_t
pthread_spinlock_t
pthread_t
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Interface Stability |Standard |
+-----------------------------+-----------------------------+
SEE ALSO
sched.h(3HEAD), time.h(3HEAD), types.h(3HEAD), pthread_attr_getguardsize(3C), pthread_attr_init(3C), pthread_attr_setscope(3C),
pthread_cancel(3C), pthread_cleanup_pop(3C), pthread_cond_init(3C), pthread_cond_signal(3C), pthread_cond_wait(3C), pthread_con-
dattr_init(3C), pthread_create(3C), pthread_detach(3C), pthread_equal(3C), pthread_exit(3C), pthread_getconcurrency(3C), pthread_getsched-
param(3C), pthread_join(3C), pthread_key_create(3C), pthread_key_delete(3C), pthread_mutex_init(3C), pthread_mutex_lock(3C),
pthread_mutex_setprioceiling(3C), pthread_mutexattr_init(3C), pthread_mutexattr_init(3C), pthread_mutexattr_init(3C), pthread_mutex-
attr_gettype(3C), pthread_mutexattr_getprotocol(3C), pthread_once(3C), pthread_rwlock_init(3C), pthread_rwlock_rdlock(3C),
pthread_rwlock_unlock(3C), pthread_rwlock_wrlock(3C), pthread_rwlockattr_getpshared(3C), pthread_rwlockattr_init(3C), pthread_self(3C),
pthread_setcancelstate(3C), pthread_setspecific(3C), attributes(5), standards(5)
SunOS 5.10 9 Sep 2004 pthread.h(3HEAD)