Discussion:
Multithread server using MPICH-2
(too old to reply)
g***@gmail.com
2008-09-18 21:12:20 UTC
Permalink
Hello,

I'm implementing a server in MPI that accepts more than one connection
from clients at the same time.
For do that I used MPI and pthreads.

What I want to do is a server that stays in a infinity loop waiting
for connections (MPI_Comm_accept(portMD, MPI_INFO_NULL, 0,
MPI_COMM_WORLD, newCommClient);). When a connection is established, he
creates a new thread and return to wait more connections. That means,
the server and the thread will work in parallel.

The function that the thread will execute calls mpi functions, like
MPI_probe, MPI_Get_count, MPI_Recv, MPI_Send, MPI_Pack and
MPI_Unpack.

The problem I'm having is that the server and the thread are not
working in parallel successfully. Sometimes, the program hangs, do
nothing, and in another times a fatal error appears.

When I put the server to sleep for a moment, before he will wait
another connection, during the time he was sleeping the created thread
works fine. Once the server wakes up and starts to wait for a
connection, things stop working.

A peace of my code (Server):
-----------------------------------------------------------------------------------------------------------------------------
// arguments passed to a thread
typedef struct
{ MPI_Comm communicator;
char * path1;
char * path2;
char * port;
} ThreadParam;

pthread_t threads[10];
int t =0;
int rc;


ThreadParam * listParam = NULL;
MPI_Comm * newCommClient;


/* server infinity loop */
while (time_out > 10)
{

newCommClient = malloc(sizeof(MPI_Comm));


/* waiting for a connection */
MPI_Comm_accept(portMD, MPI_INFO_NULL, 0, MPI_COMM_WORLD,
newCommClient);

listParam = malloc(sizeof(ThreadParam));
listParam->communicator = *newCommClient; //with this
communicator the thread will talk with
the / //
client
listParam->path1 = argv[2];
listParam->path2 = argv[4];
listParam->port = portMD;

rc = pthread_create(&threads[t], NULL, threadfunc, (void *)
listParam);

if (rc){
printf("ERROR; return code from pthread_create() is %d\n",
rc);
exit(-1);
}
//sleep(1);
t++;
}

-----------------------------------------------------------------------------------------------------------------------------
Please, I need help to solve this problem!!

Thanks very mych!

Gisele
Michael Hofmann
2008-09-19 07:46:35 UTC
Permalink
Your program definitely requires a thread-safe MPI! Maybe your MPICH-2
version is not appropriately configured.

Are you using "MPI_Init_thread" with "required = MPI_THREAD_MULTIPLE" for
initialization (instead of "MPI_Init")? What is the output of the
"provided" level of thread support?


Michael
g***@gmail.com
2008-09-19 17:33:21 UTC
Permalink
Post by Michael Hofmann
Your program definitely requires a thread-safe MPI! Maybe your MPICH-2
version is not appropriately configured.
Are you using "MPI_Init_thread" with "required = MPI_THREAD_MULTIPLE" for
initialization (instead of "MPI_Init")? What is the output of the
"provided" level of thread support?
Michael
Yes, in the code of server a put "MPI_Init_thread" with "required =
MPI_THREAD_MULTIPLE" and the provided return was 1.
I am using mpich2-1.0.7, in a core due with ubuntu, and I tried ./
configure with this options: -with-device=ch3:sock --enable-
threads=multiple, after the
problems appeared.
Nothing change the situation.
g***@gmail.com
2008-09-19 21:21:59 UTC
Permalink
Post by g***@gmail.com
Post by Michael Hofmann
Your program definitely requires a thread-safe MPI! Maybe your MPICH-2
version is not appropriately configured.
Are you using "MPI_Init_thread" with "required = MPI_THREAD_MULTIPLE" for
initialization (instead of "MPI_Init")? What is the output of the
"provided" level of thread support?
Michael
Yes, in the code of server a put "MPI_Init_thread" with "required =
MPI_THREAD_MULTIPLE" and the provided return was 1.
I am using mpich2-1.0.7, in a core due with ubuntu, and I tried ./
configure with this options: -with-device=ch3:sock --enable-
threads=multiple, after the
problems appeared.
Nothing change the situation.
People, thank you all!!!
Post by g***@gmail.com
./configure --enable-romio --without-mpe --with-pm=mpd --with-device=ch3:sock --enable-threads=multiple --with-thread-package=posix
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
rc = pthread_create(&threads[t], &attr, threadfunc, (void *)
listParam);

It works!!!

I hope not have more problems and I hope that the library is really
stable for this type of situation.

If I have any other problem I turn to send messages.
Thank you for helping!!!!
g***@gmail.com
2008-09-19 21:24:18 UTC
Permalink
Post by g***@gmail.com
Post by Michael Hofmann
Your program definitely requires a thread-safe MPI! Maybe your MPICH-2
version is not appropriately configured.
Are you using "MPI_Init_thread" with "required = MPI_THREAD_MULTIPLE" for
initialization (instead of "MPI_Init")? What is the output of the
"provided" level of thread support?
Michael
Yes, in the code of server a put "MPI_Init_thread" with "required =
MPI_THREAD_MULTIPLE" and the provided return was 1.
I am using mpich2-1.0.7, in a core due with ubuntu, and I tried ./
configure with this options: -with-device=ch3:sock --enable-
threads=multiple, after the
problems appeared.
Nothing change the situation.
People, thank you all!!!
Post by g***@gmail.com
./configure --enable-romio --without-mpe --with-pm=mpd --with-device=ch3:sock --enable-threads=multiple --with-thread-package=posix
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
rc = pthread_create(&threads[t], &attr, threadfunc, (void *)
listParam);

It works!!!

I hope not have more problems and I hope that the library is really
stable for this type of situation.

If I have any other problem I turn to send messages.
Thank you for helping!!!!

Loading...