Index: XIOS/dev/branch_openmp/extern/ep_dev/ep_allocate.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_allocate.cpp	(revision 1388)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_allocate.cpp	(revision 1388)
@@ -0,0 +1,86 @@
+#include "ep_lib.hpp"
+#include <mpi.h>
+#include "ep_declaration.hpp"
+#include "ep_mpi.hpp"
+
+namespace ep_lib
+{
+
+
+
+  int MPI_Alloc_mem(MPI_Aint size, MPI_Info info, void *baseptr)
+  {
+    ::MPI_Alloc_mem(to_mpi_aint(size), to_mpi_info(info), baseptr);
+    //::MPI_Alloc_mem(size.mpi_aint, MPI_INFO_NULL_STD, baseptr);
+    return 0;
+   }
+   
+  // int MPI_Alloc_mem(unsigned long size, MPI_Info info, void *baseptr)
+  // {
+  //   ::MPI_Alloc_mem(size, *(static_cast< ::MPI_Info*>(info.mpi_info)), baseptr);
+  //   //::MPI_Alloc_mem(size, MPI_INFO_NULL_STD, baseptr);
+  //   return 0;
+  // }
+
+  int MPI_Win_allocate (MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm, void *baseptr, MPI_Win *win)
+  {
+    int rank, rank_loc, num_ep;
+    MPI_Comm_rank(comm, &rank);
+    rank_loc = comm.ep_comm_ptr->size_rank_info[1].first;
+    num_ep = comm.ep_comm_ptr->size_rank_info[1].second;
+    
+    win->is_ep = comm.is_ep;
+
+    int num_ep_max;
+    MPI_Allreduce(&num_ep, &num_ep_max, 1, MPI_INT, MPI_MAX, comm);
+
+    assert(num_ep_max > 1);
+    
+    
+
+    if(num_ep == 1)  // server
+    {
+      for(int i=0; i<num_ep_max; i++)
+      {
+        win->server_win[i] = new ::MPI_Win;
+      }
+
+      printf("Calling MPI_Win_allocate from server, rank = %d\n", rank);
+      for(int i=0; i<num_ep_max; i++)
+      {
+        ::MPI_Win_allocate(to_mpi_aint(size), disp_unit, to_mpi_info(info), to_mpi_comm(comm.mpi_comm), baseptr, static_cast< ::MPI_Win*>(win->server_win[i]));
+        win->comm = comm;
+      }
+    }
+    else  // client
+    {
+      win->client_win = new ::MPI_Win;
+      
+      for(int i=0; i<num_ep; i++)
+      {
+        if(rank_loc == i)
+        {
+          printf("Calling MPI_Win_allocate from client, rank = %d\n", rank);
+          ::MPI_Win_allocate(to_mpi_aint(size), disp_unit, to_mpi_info(info), to_mpi_comm(comm.mpi_comm), baseptr, static_cast< ::MPI_Win*>(win->client_win)); 
+          win->comm = comm;
+        }
+        MPI_Barrier_local(comm);
+      }
+
+      if(num_ep_max > num_ep)
+      {
+        #pragma omp master
+        {
+          for(int i=0; i<num_ep_max-num_ep; i++)
+          {
+            win->null_win[i] = new ::MPI_Win;
+            ::MPI_Win_allocate(0, disp_unit, to_mpi_info(info), to_mpi_comm(comm.mpi_comm), baseptr, static_cast< ::MPI_Win*>(win->null_win[i])); 
+          }  
+        }  
+      }
+
+    }
+    return 0;
+  }
+
+}
Index: XIOS/dev/branch_openmp/extern/ep_dev/ep_lib.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_lib.cpp	(revision 1387)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_lib.cpp	(revision 1388)
@@ -255,7 +255,7 @@
 }
 
-MPI_Info to_mpi_info(void* info)
-{
-  return *(static_cast< MPI_Info* >(info));
+MPI_Info to_mpi_info(ep_lib::MPI_Info info)
+{
+  return *(static_cast< MPI_Info* >(info.mpi_info));
 }
 
Index: XIOS/dev/branch_openmp/extern/ep_dev/ep_lib.hpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_lib.hpp	(revision 1387)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_lib.hpp	(revision 1388)
@@ -69,5 +69,5 @@
   int MPI_Alloc_mem(MPI_Aint size, MPI_Info info, void *baseptr);
   
-  int MPI_Alloc_mem(unsigned long size, MPI_Info info, void *baseptr);
+  //int MPI_Alloc_mem(unsigned long size, MPI_Info info, void *baseptr);
 
 
Index: XIOS/dev/branch_openmp/extern/ep_dev/ep_lib_win.hpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_lib_win.hpp	(revision 1387)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_lib_win.hpp	(revision 1388)
@@ -23,5 +23,6 @@
                          int result_count, MPI_Datatype result_datatype, int target_rank, MPI_Aint target_disp,
                          int target_count, MPI_Datatype target_datatype, MPI_Op op, MPI_Win win);
-
+  
+  int MPI_Win_allocate (MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm, void *baseptr, MPI_Win *win);
 }
 
Index: XIOS/dev/branch_openmp/extern/ep_dev/ep_memory.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_memory.cpp	(revision 1387)
+++ 	(revision )
@@ -1,28 +1,0 @@
-#include "ep_lib.hpp"
-#include <mpi.h>
-#include "ep_declaration.hpp"
-
-namespace ep_lib
-{
-
-
-
-  int MPI_Alloc_mem(MPI_Aint size, MPI_Info info, void *baseptr)
-  {
-    ::MPI_Alloc_mem(*(static_cast< ::MPI_Aint*>(size.mpi_aint)), *(static_cast< ::MPI_Info*>(info.mpi_info)), baseptr);
-    //::MPI_Alloc_mem(size.mpi_aint, MPI_INFO_NULL_STD, baseptr);
-    return 0;
-   }
-   
-  int MPI_Alloc_mem(unsigned long size, MPI_Info info, void *baseptr)
-  {
-    ::MPI_Alloc_mem(size, *(static_cast< ::MPI_Info*>(info.mpi_info)), baseptr);
-    //::MPI_Alloc_mem(size, MPI_INFO_NULL_STD, baseptr);
-    return 0;
-  }
-
-
-
-}
-
-
Index: XIOS/dev/branch_openmp/extern/ep_dev/ep_mpi.hpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_mpi.hpp	(revision 1387)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_mpi.hpp	(revision 1388)
@@ -8,5 +8,5 @@
 MPI_Comm     to_mpi_comm(void* comm);
 MPI_Message  to_mpi_message(void* message);
-MPI_Info     to_mpi_info(void* info);
+MPI_Info     to_mpi_info(ep_lib::MPI_Info info);
 MPI_Win      to_mpi_win(void* win);
 MPI_Aint     to_mpi_aint(ep_lib::MPI_Aint aint);
Index: XIOS/dev/branch_openmp/extern/ep_dev/ep_type.hpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_type.hpp	(revision 1387)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_type.hpp	(revision 1388)
@@ -277,9 +277,9 @@
     public:
       bool is_ep;
-      void* mpi_win[12]; // client side
       MPI_Comm comm;
 
-      void* server_win[12];
+      void* server_win[16];
       void* client_win;
+      void* null_win[16];
   };
 
Index: XIOS/dev/branch_openmp/extern/ep_dev/ep_win.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_win.cpp	(revision 1387)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_win.cpp	(revision 1388)
@@ -35,5 +35,5 @@
       for(int i=0; i<num_ep_max; i++)
       {
-        ::MPI_Win_create(base, to_mpi_aint(size.mpi_aint), disp_unit, to_mpi_info(info.mpi_info), to_mpi_comm(comm.mpi_comm), static_cast< ::MPI_Win*>(win->server_win[i]));
+        ::MPI_Win_create(base, to_mpi_aint(size), disp_unit, to_mpi_info(info), to_mpi_comm(comm.mpi_comm), static_cast< ::MPI_Win*>(win->server_win[i]));
         win->comm = comm;
       }
@@ -43,10 +43,10 @@
       win->client_win = new ::MPI_Win;
       
-      for(int i=0; i<num_ep_max; i++)
+      for(int i=0; i<num_ep; i++)
       {
         if(rank_loc == i)
         {
           printf("Calling MPI_Win_create from client, rank = %d\n", rank);
-          ::MPI_Win_create(base, to_mpi_aint(size.mpi_aint), disp_unit, to_mpi_info(info.mpi_info), to_mpi_comm(comm.mpi_comm), static_cast< ::MPI_Win*>(win->client_win)); 
+          ::MPI_Win_create(base, to_mpi_aint(size), disp_unit, to_mpi_info(info), to_mpi_comm(comm.mpi_comm), static_cast< ::MPI_Win*>(win->client_win)); 
           win->comm = comm;
         }
@@ -54,9 +54,17 @@
       }
 
-      // #pragma omp critical (win_create)
-      // {
-      //   ::MPI_Win_create(base, to_mpi_aint(size.mpi_aint), disp_unit, to_mpi_info(info.mpi_info), to_mpi_comm(comm.mpi_comm), static_cast< ::MPI_Win*>(win->client_win)); 
-      //   win->comm = comm;
-      // }
+      if(num_ep_max > num_ep)
+      {
+
+        #pragma omp master
+        {
+          for(int i=0; i<num_ep_max-num_ep; i++)
+          {
+            win->null_win[i] = new ::MPI_Win;
+            ::MPI_Win_create(NULL, 0, disp_unit, to_mpi_info(info), to_mpi_comm(comm.mpi_comm), static_cast< ::MPI_Win*>(win->null_win[i])); 
+          }  
+        }  
+      }
+
     }
     return 0;
@@ -90,5 +98,5 @@
     else
     {
-      for(int i=0; i<num_ep_max; i++)
+      for(int i=0; i<num_ep; i++)
       {
         if(rank_loc == i)
@@ -99,4 +107,17 @@
         MPI_Barrier_local(win->comm);
       }
+
+
+      if(num_ep_max > num_ep)
+      {
+        #pragma omp master
+        {
+          for(int i=0; i<num_ep_max-num_ep; i++)
+          {
+            ::MPI_Win_free(static_cast< ::MPI_Win*>(win->null_win[i])); 
+          }  
+        }  
+      }
+
     }
     return 0;
@@ -126,5 +147,5 @@
     else
     {
-      for(int i=0; i<num_ep_max; i++)
+      for(int i=0; i<num_ep; i++)
       {
         if(rank_loc == i)
@@ -134,4 +155,16 @@
         }
         MPI_Barrier_local(win.comm);
+      }
+
+
+      if(num_ep_max > num_ep)
+      {
+        #pragma omp master
+        {
+          for(int i=0; i<num_ep_max-num_ep; i++)
+          {
+            ::MPI_Win_fence(assert, *static_cast< ::MPI_Win*>(win.null_win[i])); 
+          }  
+        }  
       }
     }
Index: XIOS/dev/branch_openmp/extern/ep_dev/main.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/main.cpp	(revision 1387)
+++ XIOS/dev/branch_openmp/extern/ep_dev/main.cpp	(revision 1388)
@@ -637,5 +637,5 @@
   {
     printf("Proc %d is client\n", mpi_rank);
-    num_threads = 2;
+    num_threads = 2+mpi_rank;
   }
   else
@@ -730,6 +730,18 @@
                          1, MPI_INT, MPI_SUM, ep_win);
     }
-
-    
+    
+    MPI_Win_fence(0, ep_win);
+
+    MPI_Win ep_win_allocated;
+    int* baseptr = new int[10];
+    MPI_Aint base_size = 4;
+
+    MPI_Win_allocate (base_size, sizeof(int), info, comm, baseptr, &ep_win_allocated);
+
+    MPI_Win_fence(0, ep_win_allocated);
+
+    MPI_Win_free(&ep_win_allocated);
+    delete[] baseptr;
+
     MPI_Win_free(&ep_win);
     printf("rank = %d, buf = %d, local_buf = %d, result_buf = %d\n", rank, buf, local_buf, result_buf);
