diff --git a/src/sys/mpiuni/mpi.c b/src/sys/mpiuni/mpi.c index ee27b45..56651bd 100644 --- a/src/sys/mpiuni/mpi.c +++ b/src/sys/mpiuni/mpi.c @@ -24,6 +24,9 @@ int MPIUNI_DATASIZE[10] = {sizeof(int),sizeof(float),sizeof(double),2*sizeof(do */ #define MAX_ATTR 128 +#define MAX_COMM 128 + +static int MaxComm = 2; typedef struct { void *attribute_val; @@ -36,7 +39,7 @@ typedef struct { } MPI_Attr_keyval; static MPI_Attr_keyval attr_keyval[MAX_ATTR]; -static MPI_Attr attr[4][MAX_ATTR]; +static MPI_Attr attr[MAX_COMM][MAX_ATTR]; static int num_attr = 1,mpi_tag_ub = 100000000; #if defined(__cplusplus) @@ -90,7 +93,7 @@ int MPI_Keyval_free(int *keyval) int MPI_Attr_put(MPI_Comm comm,int keyval,void *attribute_val) { - if (comm-1 < 0 || comm-1 > 3) return 1; + if (comm-1 < 0 || comm-1 > MaxComm) return 1; attr[comm-1][keyval].active = 1; attr[comm-1][keyval].attribute_val = attribute_val; return MPI_SUCCESS; @@ -98,7 +101,7 @@ int MPI_Attr_put(MPI_Comm comm,int keyval,void *attribute_val) int MPI_Attr_delete(MPI_Comm comm,int keyval) { - if (comm-1 < 0 || comm-1 > 3) return 1; + if (comm-1 < 0 || comm-1 > MaxComm) return 1; if (attr[comm-1][keyval].active && attr_keyval[keyval].del) { void *save_attribute_val = attr[comm-1][keyval].attribute_val; attr[comm-1][keyval].active = 0; @@ -110,30 +113,26 @@ int MPI_Attr_delete(MPI_Comm comm,int keyval) int MPI_Attr_get(MPI_Comm comm,int keyval,void *attribute_val,int *flag) { - if (comm-1 < 0 || comm-1 > 3) return 1; + if (comm-1 < 0 || comm-1 > MaxComm) return 1; if (!keyval) Keyval_setup(); *flag = attr[comm-1][keyval].active; *(void**)attribute_val = attr[comm-1][keyval].attribute_val; return MPI_SUCCESS; } -static int dups[4] = {1,1,1,1}; int MPI_Comm_create(MPI_Comm comm,MPI_Group group,MPI_Comm *newcomm) { - if (comm-1 < 0 || comm-1 > 3) return 1; - dups[comm-1]++; - *newcomm = comm; + if (comm-1 < 0 || comm-1 > MaxComm) return 1; + if (MaxComm > MAX_COMM) return MPI_FAILURE; + *newcomm = MaxComm++; return MPI_SUCCESS; } int MPI_Comm_dup(MPI_Comm comm,MPI_Comm *out) { - if (comm-1 < 0 || comm-1 > 3) return 1; - if (comm == MPI_COMM_WORLD || comm == MPI_COMM_SELF) *out = comm + 2; - else { - *out = comm; - dups[comm-1]++; - } + if (comm-1 < 0 || comm-1 > MaxComm) return 1; + if (MaxComm > MAX_COMM) return MPI_FAILURE; + *out = MaxComm++; return 0; } @@ -141,27 +140,26 @@ int MPI_Comm_free(MPI_Comm *comm) { int i; - if (*comm-1 < 0 || *comm-1 > 3) return 1; - if (dups[*comm-1] == 1) { - for (i=0; i 1) dups[*comm-1]--; + if (*comm-1 < 0 || *comm-1 > MaxComm) return 1; + for (i=0; i MaxComm) return 1; *size=1; return MPI_SUCCESS; } int MPI_Comm_rank(MPI_Comm comm, int *rank) { + if (comm-1 < 0 || comm-1 > MaxComm) return 1; *rank=0; return MPI_SUCCESS; }