#include <algorithm>
#include "private.h"
-#include "xbt/replay.h"
#include "mc/mc.h"
#include "src/mc/mc_replay.h"
#include "src/simix/smx_private.h"
namespace simgrid{
namespace smpi{
+
Request::Request(){}
Request::Request(void *buf, int count, MPI_Datatype datatype, int src, int dst, int tag, MPI_Comm comm, unsigned flags) : buf_(buf), old_type_(datatype), src_(src), dst_(dst), tag_(tag), comm_(comm), flags_(flags)
{
void *old_buf = nullptr;
- s_smpi_subtype_t *subtype = static_cast<s_smpi_subtype_t*>(datatype->substruct);
- if((((flags & RECV) != 0) && ((flags & ACCUMULATE) !=0)) || (datatype->sizeof_substruct != 0)){
+ if((((flags & RECV) != 0) && ((flags & ACCUMULATE) !=0)) || (datatype->flags() & DT_FLAG_DERIVED)){
// This part handles the problem of non-contiguous memory
old_buf = buf;
- buf_ = count==0 ? nullptr : xbt_malloc(count*smpi_datatype_size(datatype));
- if ((datatype->sizeof_substruct != 0) && ((flags & SEND) != 0)) {
- subtype->serialize(old_buf, buf_, count, datatype->substruct);
+ buf_ = count==0 ? nullptr : xbt_malloc(count*datatype->size());
+ if ((datatype->flags() & DT_FLAG_DERIVED) && ((flags & SEND) != 0)) {
+ datatype->serialize(old_buf, buf_, count);
}
}
// This part handles the problem of non-contiguous memory (for the unserialisation at the reception)
old_buf_ = old_buf;
- size_ = smpi_datatype_size(datatype) * count;
- smpi_datatype_use(datatype);
- comm_->use();
+ size_ = datatype->size() * count;
+ datatype->ref();
+ comm_->ref();
action_ = nullptr;
detached_ = 0;
detached_sender_ = nullptr;
return detached_;
}
+size_t Request::size(){
+ return size_;
+}
+
+size_t Request::real_size(){
+ return real_size_;
+}
-void Request::unuse(MPI_Request* request)
+
+void Request::unref(MPI_Request* request)
{
if((*request) != MPI_REQUEST_NULL){
(*request)->refcount_--;
if((*request)->refcount_<0) xbt_die("wrong refcount");
if((*request)->refcount_==0){
- smpi_datatype_unuse((*request)->old_type_);
- (*request)->comm_->unuse();
+ Datatype::unref((*request)->old_type_);
+ Comm::unref((*request)->comm_);
(*request)->print_request("Destroying");
delete *request;
*request = MPI_REQUEST_NULL;
MPI_Status stats[2];
int myid=smpi_process_index();
if ((comm->group()->index(dst) == myid) && (comm->group()->index(src) == myid)){
- smpi_datatype_copy(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype);
+ Datatype::copy(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype);
return;
}
requests[0] = isend_init(sendbuf, sendcount, sendtype, dst, sendtag, comm);
requests[1] = irecv_init(recvbuf, recvcount, recvtype, src, recvtag, comm);
startall(2, requests);
waitall(2, requests, stats);
- unuse(&requests[0]);
- unuse(&requests[1]);
+ unref(&requests[0]);
+ unref(&requests[1]);
if(status != MPI_STATUS_IGNORE) {
// Copy receive status
*status = stats[1];
detached_ = 1;
XBT_DEBUG("Send request %p is detached", this);
refcount_++;
- if(old_type_->sizeof_substruct == 0){
+ if(!(old_type_->flags() & DT_FLAG_DERIVED)){
oldbuf = buf_;
if (!smpi_process_get_replaying() && oldbuf != nullptr && size_!=0){
if((smpi_privatize_global_variables != 0)
if (xbt_cfg_get_boolean("smpi/grow-injected-times"))
nsleeps++;
}
- unuse(&request);
+ unref(&request);
}
req->print_request("Finishing");
MPI_Datatype datatype = req->old_type_;
- if(((req->flags_ & ACCUMULATE) != 0) || (datatype->sizeof_substruct != 0)){
+ if(((req->flags_ & ACCUMULATE) != 0) || (datatype->flags() & DT_FLAG_DERIVED)){
if (!smpi_process_get_replaying()){
if( smpi_privatize_global_variables != 0 && (static_cast<char*>(req->old_buf_) >= smpi_start_data_exe)
&& ((char*)req->old_buf_ < smpi_start_data_exe + smpi_size_data_exe )){
}
}
- if(datatype->sizeof_substruct != 0){
+ if(datatype->flags() & DT_FLAG_DERIVED){
// This part handles the problem of non-contignous memory the unserialization at the reception
- s_smpi_subtype_t *subtype = static_cast<s_smpi_subtype_t*>(datatype->substruct);
- if(req->flags_ & RECV)
- subtype->unserialize(req->buf_, req->old_buf_, req->real_size_/smpi_datatype_size(datatype) ,
- datatype->substruct, req->op_);
+ if((req->flags_ & RECV) && datatype->size()!=0)
+ datatype->unserialize(req->buf_, req->old_buf_, req->real_size_/datatype->size() , req->op_);
xbt_free(req->buf_);
}else if(req->flags_ & RECV){//apply op on contiguous buffer for accumulate
- int n =req->real_size_/smpi_datatype_size(datatype);
- req->op_->apply(req->buf_, req->old_buf_, &n, &datatype);
+ int n =req->real_size_/datatype->size();
+ req->op_->apply(req->buf_, req->old_buf_, &n, datatype);
xbt_free(req->buf_);
}
}
simcall_process_sleep(sleeptime);
XBT_DEBUG("receiving size of %zu : sleep %f ", req->real_size_, sleeptime);
}
- unuse(&(req->detached_sender_));
+ unref(&(req->detached_sender_));
}
if(req->flags_ & PERSISTENT)
req->action_ = nullptr;
req->flags_ |= FINISHED;
- unuse(request);
+ unref(request);
}
return count;
}
+MPI_Request Request::f2c(int id) {
+ char key[KEY_SIZE];
+ if(id==MPI_FORTRAN_REQUEST_NULL)
+ return static_cast<MPI_Request>(MPI_REQUEST_NULL);
+ return static_cast<MPI_Request>(xbt_dict_get(F2C::f2c_lookup_, get_key_id(key, id)));
+}
+
+int Request::add_f() {
+ if(F2C::f2c_lookup_==nullptr){
+ F2C::f2c_lookup_=xbt_dict_new_homogeneous(nullptr);
+ }
+ char key[KEY_SIZE];
+ xbt_dict_set(F2C::f2c_lookup_, get_key_id(key, F2C::f2c_id_), this, nullptr);
+ F2C::f2c_id_++;
+ return F2C::f2c_id_-1;
+}
+
+void Request::free_f(int id) {
+ char key[KEY_SIZE];
+ if(id!=MPI_FORTRAN_REQUEST_NULL)
+ xbt_dict_remove(F2C::f2c_lookup_, get_key_id(key, id));
+}
+
+
}
}