|
From: <sv...@va...> - 2006-03-10 14:51:23
|
Author: sewardj
Date: 2006-03-10 14:51:19 +0000 (Fri, 10 Mar 2006)
New Revision: 5738
Log:
* try to handle MPI_{LONG,DOUBLE,SHORT}_INT better (despite the best
efforts of the MPI spec to screw this up)
* Add locking to accesses to the "sReqs" shadow-requests table
used to keep track of uncompleted MPI_Irecv's. This might
even mean the wrappers are thread-safe now :-)
Modified:
trunk/auxprogs/mpiwrap.c
Modified: trunk/auxprogs/mpiwrap.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/auxprogs/mpiwrap.c 2006-03-10 13:43:49 UTC (rev 5737)
+++ trunk/auxprogs/mpiwrap.c 2006-03-10 14:51:19 UTC (rev 5738)
@@ -451,14 +451,27 @@
/* Hmm. Perhaps it's a named struct? Unfortunately we can't
take them to bits so we have to do a really ugly hack, which
makes assumptions about how the MPI implementation has laid
- out these types.
+ out these types. At least Open MPI 1.0.1 appears to put
+ the 'val' field first.
*/
if (ty =3D=3D MPI_LONG_INT) {
- typedef struct { long dbl; int loc; } Ty;
- f(base + offsetof(Ty,dbl), sizeof(long));
+ typedef struct { long val; int loc; } Ty;
+ f(base + offsetof(Ty,val), sizeof(long));
f(base + offsetof(Ty,loc), sizeof(int));
return;
}
+ if (ty =3D=3D MPI_DOUBLE_INT) {
+ typedef struct { double val; int loc; } Ty;
+ f(base + offsetof(Ty,val), sizeof(double));
+ f(base + offsetof(Ty,loc), sizeof(int));
+ return;
+ }
+ if (ty =3D=3D MPI_SHORT_INT) {
+ typedef struct { short val; int loc; } Ty;
+ f(base + offsetof(Ty,val), sizeof(short));
+ f(base + offsetof(Ty,loc), sizeof(int));
+ return;
+ }
goto unhandled;
/*NOTREACHED*/
}
@@ -643,7 +656,9 @@
}
=20
=20
-void walk_type_EXTERNALLY_VISIBLE
+/* Hook so it's visible from outside (can be handy to dlopen/dlsym
+ it) */
+void mpiwrap_walk_type_EXTERNALLY_VISIBLE
( void(*f)(void*,long), char* base, MPI_Datatype ty )
{
return walk_type(f, base, ty);
@@ -848,9 +863,19 @@
static ShadowRequest* sReqs =3D NULL;
static int sReqs_size =3D 0;
static int sReqs_used =3D 0;
-//static pthread_mutex_t sReqs_lock =3D PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t sReqs_lock =3D PTHREAD_MUTEX_INITIALIZER;
=20
+#define LOCK_SREQS \
+ do { int pr =3D pthread_mutex_lock(&sReqs_lock); \
+ assert(pr =3D=3D 0); \
+ } while (0)
=20
+#define UNLOCK_SREQS \
+ do { int pr =3D pthread_mutex_unlock(&sReqs_lock); \
+ assert(pr =3D=3D 0); \
+ } while (0)
+
+
/* Ensure the sReqs expandable array has at least one free slot, by
copying it into a larger one if necessary. NOTE: sReqs_lock is
held throughout this procedure.*/
@@ -862,7 +887,7 @@
sReqs_size =3D sReqs_size=3D=3D0 ? 2 : 2*sReqs_size;
sReqs2 =3D malloc( sReqs_size * sizeof(ShadowRequest) );
if (sReqs2 =3D=3D NULL) {
- /* UNLOCK */
+ UNLOCK_SREQS;
barf("add_shadow_Request: malloc failed.\n");
}
for (i =3D 0; i < sReqs_used; i++)
@@ -882,14 +907,14 @@
{
ShadowRequest* ret =3D NULL;
int i;
- /* LOCK */
+ LOCK_SREQS;
for (i =3D 0; i < sReqs_used; i++) {
if (sReqs[i].inUse && eq_MPI_Request(sReqs[i].key,request)) {
ret =3D &sReqs[i];
break;
}
}
- /* UNLOCK */
+ UNLOCK_SREQS;
return ret;
}
=20
@@ -899,14 +924,14 @@
static void delete_shadow_Request ( MPI_Request request )
{
int i;
- /* LOCK */
+ LOCK_SREQS;
for (i =3D 0; i < sReqs_used; i++) {
if (sReqs[i].inUse && eq_MPI_Request(sReqs[i].key,request)) {
sReqs[i].inUse =3D False;
break;
}
}
- /* UNLOCK */
+ UNLOCK_SREQS;
}
=20
=20
@@ -918,7 +943,7 @@
MPI_Datatype datatype )
{
int i, ix =3D -1;
- /* LOCK */
+ LOCK_SREQS;
assert(sReqs_used >=3D 0);
assert(sReqs_size >=3D 0);
assert(sReqs_used <=3D sReqs_size);
@@ -961,13 +986,15 @@
sReqs[ix].count =3D count;
sReqs[ix].datatype =3D datatype;
=20
- /* UNLOCK */
+ UNLOCK_SREQS;
if (opt_verbosity > 1)
fprintf(stderr, "%s %5d: sReq+ 0x%lx -> b/c/d %p/%d/0x%lx [slot %d=
]\n",
preamble, my_pid, (unsigned long)request,=20
buf, count, (long)datatype, ix);
}
=20
+#undef LOCK_SREQS
+#undef UNLOCK_SREQS
=20
static void maybe_complete ( Bool error_in_status,
MPI_Request request_before,
|