+
+int Request::grequest_start( MPI_Grequest_query_function *query_fn, MPI_Grequest_free_function *free_fn, MPI_Grequest_cancel_function *cancel_fn, void *extra_state, MPI_Request *request){
+
+ *request = new Request();
+ (*request)->flags_ |= MPI_REQ_GENERALIZED;
+ (*request)->flags_ |= MPI_REQ_PERSISTENT;
+ (*request)->refcount_ = 1;
+ ((*request)->generalized_funcs)=xbt_new0(s_smpi_mpi_generalized_request_funcs_t ,1);
+ ((*request)->generalized_funcs)->query_fn=query_fn;
+ ((*request)->generalized_funcs)->free_fn=free_fn;
+ ((*request)->generalized_funcs)->cancel_fn=cancel_fn;
+ ((*request)->generalized_funcs)->extra_state=extra_state;
+ ((*request)->generalized_funcs)->cond = simgrid::s4u::ConditionVariable::create();
+ ((*request)->generalized_funcs)->mutex = simgrid::s4u::Mutex::create();
+ return MPI_SUCCESS;
+}
+
+int Request::grequest_complete( MPI_Request request){
+ if ((!(request->flags_ & MPI_REQ_GENERALIZED)) || request->generalized_funcs->mutex==NULL)
+ return MPI_ERR_REQUEST;
+ request->generalized_funcs->mutex->lock();
+ request->flags_ |= MPI_REQ_COMPLETE; // in case wait would be called after complete
+ request->generalized_funcs->cond->notify_one();
+ request->generalized_funcs->mutex->unlock();
+ return MPI_SUCCESS;
+}
+