Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Typo.
[simgrid.git] / src / smpi / smpi_f77.c
index d32614f..95c40d7 100644 (file)
@@ -1,8 +1,8 @@
-/* Copyright (c) 2010-2013. The SimGrid Team.
+/* Copyright (c) 2010-2014. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
 * under the terms of the license (GNU LGPL) which comes with this package. */
+ * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include <limits.h>
 #include <stdio.h>
@@ -20,13 +20,27 @@ static xbt_dict_t datatype_lookup = NULL;
 static xbt_dict_t op_lookup = NULL;
 static int running_processes = 0;
 
-
-
-/* Convert between Fortran and C MPI_BOTTOM */
-#define F2C_BOTTOM(addr)    ((addr!=MPI_IN_PLACE && *(int*)addr == MPI_FORTRAN_BOTTOM) ? MPI_BOTTOM : (addr))
-#define F2C_IN_PLACE(addr)  ((addr!=MPI_BOTTOM &&*(int*)addr == MPI_FORTRAN_IN_PLACE) ? MPI_IN_PLACE : (addr))
-#define F2C_STATUS_IGNORE(addr) ((*(int*)addr == MPI_FORTRAN_STATUS_IGNORE) ? MPI_STATUS_IGNORE : (addr))
-#define F2C_STATUSES_IGNORE(addr) ((*(int*)addr == MPI_FORTRAN_STATUSES_IGNORE) ? MPI_STATUSES_IGNORE : (addr))
+/* Bindings for MPI special values */
+union u_smpi_common {
+  struct s_smpi_common {
+    integer _MPI_IN_PLACE;
+    integer _MPI_BOTTOM;
+    integer _MPI_STATUS_IGNORE;
+    integer _MPI_STATUSES_IGNORE;
+  } *f77;                       /* with f2c, remains NULL with gfortran */
+  struct s_smpi_common f90;     /* with gfortran */
+} smpi_ = { NULL };
+
+/* Convert between Fortran and C */
+#define F2C_ADDR(addr, val)                                             \
+  (((void *)(addr) == (void *)(smpi_.f77                                \
+                               ? &smpi_.f77[smpi_current_rank]._ ## val \
+                               : &smpi_.f90._ ## val))                  \
+   ? (val) : (void *)(addr))
+#define F2C_BOTTOM(addr)          F2C_ADDR(addr, MPI_BOTTOM)
+#define F2C_IN_PLACE(addr)        F2C_ADDR(addr, MPI_IN_PLACE)
+#define F2C_STATUS_IGNORE(addr)   F2C_ADDR(addr, MPI_STATUS_IGNORE)
+#define F2C_STATUSES_IGNORE(addr) F2C_ADDR(addr, MPI_STATUSES_IGNORE)
 
 #define KEY_SIZE (sizeof(int) * 2 + 1)
 
@@ -213,13 +227,10 @@ void mpi_finalize_(int* ierr) {
    running_processes--;
    if(running_processes==0){
      xbt_dict_free(&op_lookup);
-     op_lookup = NULL;
      xbt_dict_free(&datatype_lookup);
-     datatype_lookup = NULL;
      xbt_dict_free(&request_lookup);
-     request_lookup = NULL;
+     xbt_dict_free(&group_lookup);
      xbt_dict_free(&comm_lookup);
-     comm_lookup = NULL;
    }
 }