Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

pthreads in a cluster

84 views
Skip to first unread message

daniel_unb

unread,
Jun 21, 2006, 6:25:18 PM6/21/06
to
Hello,
I am trying to use pthreads to distribute a job into the several nodes
of an openmosix linux cluster .
Here is the code I wrote (Hello World with small modifications)
---------------------------------------------------------------------------------------------------------------------------------------
#include <pthread.h>
#include <stdio.h>
#define NUM_THREADS 5

void *PrintHello(void *threadid)
{int j,i,n;
for(j=0;j<100000;j++){
n=0;
for(i=0;i<j;i++){
n=n+i;
}
printf("%d \n",n);
}
printf("\n%d: Hello World!\n", threadid);
pthread_exit(NULL);
}

int main (int argc, char *argv[])
{
pthread_t threads[NUM_THREADS];
int rc, t;
for(t=0; t<NUM_THREADS; t++){
printf("Creating thread %d\n", t);
rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t);
if (rc){
printf("ERROR; return code from pthread_create() is %d\n",
rc);
exit(-1);
}
}
pthread_exit(NULL);
----------------------------------------------------------------------------------------------------------------------------------------
This small program was successfully compiled (gcc -pthread). However,
when running, it was
not distributed into 5 distinct nodes. The 5 processes generated by the
executable began to run
on a single node.

Please, does anyone knows what should be done in order to distribute
each process to a different
node.
Thank you very much,
Daniel

dav...@webmaster.com

unread,
Jun 22, 2006, 1:35:36 AM6/22/06
to

daniel_unb wrote:

> Please, does anyone knows what should be done in order to distribute
> each process to a different
> node.

You only have one process, it just has five threads. Unfortunately,
linux kernel types often use the term 'process' when they mean KSE
(kernel scheduling entity). On Linux, OpenMOSIX can only migrate
processes that contain a single thread.

Imagine for a second if OpenMOSIX migrated one thread of your process.
There would now be two threads in a process that are supposed to have
the same address space. What address space would that be?

This could theoretically be done if OpenMOSIX maintained a virtual
address space for each entity it migrated. However, this would be a
self-defeating proposition because the cost of keeping the address
spaces in synch would outweigh the benefits.

OpenMOSIX, however, could benefit from learning how to migrate all the
threads in a single process. This would reduce its limitation from
being unable to migrate any multi-threaded processes to being unable to
migrate non-standardly multi-threaded processes. (For example, one
still could not migrate two KSE's that shared an address space but not
a file descriptor table.)

DS

daniel_unb

unread,
Jun 22, 2006, 6:03:12 AM6/22/06
to
Hello David,
Thank you for answering promptly. Please, let me ask a more basic
question:
what should be used to do parallel codes, mpi, pthreads? Is there a
book for non experts
with practical examples?
Thanks a lot,
Daniel

dav...@webmaster.com escreveu:

Chris Friesen

unread,
Jun 22, 2006, 2:16:31 PM6/22/06
to
daniel_unb wrote:

> what should be used to do parallel codes, mpi, pthreads? Is there a
> book for non experts with practical examples?

It is going to depend somewhat on how much effort you want to put in vs
how much speed you need. Generally, the easier it is to code, the
slower it will be.

For instance, if you just forked multiple processes and had them talk to
each other via sockets, then OpenMOSIX would scale them transparently.
However, you'd have protocol overhead since OpenMOSIX uses UDP.

If you know all of your cluster nodes and they're all on the same local
subnet, you could explicitly spawn tasks to each node and use raw
ethernet for communication, getting rid of some of the protocol overhead.

Chris

daniel_unb

unread,
Jun 23, 2006, 11:04:56 AM6/23/06
to
Hello Chris,
thank you for email. I do not intend to put to much effort, at first.
It is an ansi C
code in which the different tasks are indepent loops.
The question is really that: what should be used to spawn tasks to each
node
using ansi C?
Please, do you know where could I look to learn how to do this? Is
there a book
with many examples?
Thanks,
Daniel

Chris Friesen escreveu:

dav...@webmaster.com

unread,
Jun 23, 2006, 7:02:54 PM6/23/06
to

daniel_unb wrote:
> Hello David,
> Thank you for answering promptly. Please, let me ask a more basic
> question:
> what should be used to do parallel codes, mpi, pthreads? Is there a
> book for non experts
> with practical examples?

That's a tough question and the answer really depends upon the
specifics of your application and how much work you are willing to put
in to get every last bit of possible performance. If you want to use
OpenMOSIX, just model the task as multiple single-threaded processes.
OpenMOSIX should be able to migrate this just fine.

DS

daniel_unb

unread,
Jul 4, 2006, 2:54:03 PM7/4/06
to
Hello to everybody,
I wrote the following code using standard gnu C compiler, gcc

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <math.h>
void fib(void ){
int i,j,n;
n=0;
for(i=0;i<1000000;i++){
for(j=0;j<i;j++){
n=n+j;
}
printf(,"%d \n",n);
}
}
int main()
{
int pid[3],j ;
for(j=0;j<3;j++){
pid[j]=fork();
}
if(pid[0]!=0){
fib();
}
else if(pid[1]!=0){
fib();
}
else if(pid[2]!=0){
fib();
}
else;
}

This above code did correctly compile and run on a linux cluster with
openmosix.
Apparently, using mtop, it can be seen that the different tasks were
distributed to the nodes.
This should provide an example of doing parallel codes in a linux
cluster with openmosix
using C.
Please, anyone correct me if I am wrong.

There is an internet address with a more elaborate example (in
portughese) using fork
http://www.dca.ufrn.br/~adelardo/cursos/DCA409/node34.html
Thank you very much
Daniel


dav...@webmaster.com escreveu:

0 new messages