template <class I> static I wait_any(I first, I last)
{
// Map to dynar<Synchro*>:
- xbt_dynar_t comms = xbt_dynar_new(sizeof(simgrid::kernel::activity::ActivityImpl*), NULL);
+ xbt_dynar_t comms = xbt_dynar_new(sizeof(simgrid::kernel::activity::ActivityImpl*), [](void*ptr){
+ intrusive_ptr_release((simgrid::kernel::activity::ActivityImpl*)ptr);
+ });
for (I iter = first; iter != last; iter++) {
Comm& comm = **iter;
if (comm.state_ == inited)
comm.start();
xbt_assert(comm.state_ == started);
- xbt_dynar_push_as(comms, simgrid::kernel::activity::ActivityImpl*, comm.pimpl_);
+ intrusive_ptr_add_ref(comm.pimpl_.get());
+ xbt_dynar_push_as(comms, simgrid::kernel::activity::ActivityImpl*, comm.pimpl_.get());
}
// Call the underlying simcall:
int idx = simcall_comm_waitany(comms, -1);
template <class I> static I wait_any_for(I first, I last, double timeout)
{
// Map to dynar<Synchro*>:
- xbt_dynar_t comms = xbt_dynar_new(sizeof(simgrid::kernel::activity::ActivityImpl*), NULL);
+ xbt_dynar_t comms = xbt_dynar_new(sizeof(simgrid::kernel::activity::ActivityImpl*), [](void*ptr){
+ intrusive_ptr_release((simgrid::kernel::activity::ActivityImpl*)ptr);
+ });
for (I iter = first; iter != last; iter++) {
Comm& comm = **iter;
if (comm.state_ == inited)
comm.start();
xbt_assert(comm.state_ == started);
- xbt_dynar_push_as(comms, simgrid::kernel::activity::ActivityImpl*, comm.pimpl_);
+ intrusive_ptr_add_ref(comm.pimpl_.get());
+ xbt_dynar_push_as(comms, simgrid::kernel::activity::ActivityImpl*, comm.pimpl_.get());
}
// Call the underlying simcall:
int idx = simcall_comm_waitany(comms, timeout);
int finished_index = -1;
/* create the equivalent dynar with SIMIX objects */
- xbt_dynar_t s_comms = xbt_dynar_new(sizeof(smx_activity_t), nullptr);
+ xbt_dynar_t s_comms = xbt_dynar_new(sizeof(smx_activity_t), [](void*ptr){
+ intrusive_ptr_release((simgrid::kernel::activity::ActivityImpl*)ptr);
+ });
msg_comm_t comm;
unsigned int cursor;
xbt_dynar_foreach(comms, cursor, comm) {
- xbt_dynar_push(s_comms, &comm->s_comm);
+ intrusive_ptr_add_ref(comm->s_comm.get());
+ xbt_dynar_push_as(s_comms, simgrid::kernel::activity::ActivityImpl*, comm->s_comm.get());
}
msg_error_t status = MSG_OK;
void simcall_HANDLER_comm_waitany(smx_simcall_t simcall, xbt_dynar_t synchros, double timeout)
{
- smx_activity_t synchro;
- unsigned int cursor = 0;
-
if (MC_is_active() || MC_record_replay_is_active()){
if (timeout > 0.0)
xbt_die("Timeout not implemented for waitany in the model-checker");
int idx = SIMCALL_GET_MC_VALUE(simcall);
- synchro = xbt_dynar_get_as(synchros, idx, smx_activity_t);
+ smx_activity_t synchro = xbt_dynar_get_as(synchros, idx, smx_activity_t);
synchro->simcalls.push_back(simcall);
simcall_comm_waitany__set__result(simcall, idx);
synchro->state = SIMIX_DONE;
});
}
- xbt_dynar_foreach(synchros, cursor, synchro){
+ unsigned int cursor;
+ simgrid::kernel::activity::ActivityImpl* ptr;
+ xbt_dynar_foreach(synchros, cursor, ptr){
+ smx_activity_t synchro = simgrid::kernel::activity::ActivityImplPtr(ptr);
/* associate this simcall to the the synchro */
synchro->simcalls.push_back(simcall);
void SIMIX_waitany_remove_simcall_from_actions(smx_simcall_t simcall)
{
- smx_activity_t synchro;
unsigned int cursor = 0;
xbt_dynar_t synchros = simcall_comm_waitany__get__comms(simcall);
- xbt_dynar_foreach(synchros, cursor, synchro) {
+ simgrid::kernel::activity::ActivityImpl* ptr;
+ xbt_dynar_foreach(synchros, cursor, ptr){
+ smx_activity_t synchro = simgrid::kernel::activity::ActivityImplPtr(ptr);
+
// Remove the first occurence of simcall:
auto i = boost::range::find(synchro->simcalls, simcall);
if (i != synchro->simcalls.end())
count++;
if (status != MPI_STATUSES_IGNORE)
status[i] = *pstat;
- if ((requests[i] != MPI_REQUEST_NULL) && requests[i]->flags_ & NON_PERSISTENT)
+ if ((requests[i] != MPI_REQUEST_NULL) && (requests[i]->flags_ & NON_PERSISTENT))
requests[i] = MPI_REQUEST_NULL;
}
} else {
int Request::waitany(int count, MPI_Request requests[], MPI_Status * status)
{
s_xbt_dynar_t comms; // Keep it on stack to save some extra mallocs
- int i;
int size = 0;
int index = MPI_UNDEFINED;
- int *map;
if(count > 0) {
// Wait for a request to complete
- xbt_dynar_init(&comms, sizeof(smx_activity_t), nullptr);
- map = xbt_new(int, count);
+ xbt_dynar_init(&comms, sizeof(smx_activity_t), [](void*ptr){
+ intrusive_ptr_release((simgrid::kernel::activity::ActivityImpl*)ptr);
+ });
+ int *map = xbt_new(int, count);
XBT_DEBUG("Wait for one of %d", count);
- for(i = 0; i < count; i++) {
+ for(int i = 0; i < count; i++) {
if (requests[i] != MPI_REQUEST_NULL && not(requests[i]->flags_ & PREPARED) &&
not(requests[i]->flags_ & FINISHED)) {
if (requests[i]->action_ != nullptr) {
XBT_DEBUG("Waiting any %p ", requests[i]);
- xbt_dynar_push(&comms, &requests[i]->action_);
+ intrusive_ptr_add_ref(requests[i]->action_.get());
+ xbt_dynar_push_as(&comms, simgrid::kernel::activity::ActivityImpl*, requests[i]->action_.get());
map[size] = i;
size++;
} else {
}
}
}
- if(size > 0) {
- i = simcall_comm_waitany(&comms, -1);
+ if (size > 0) {
+ XBT_DEBUG("Enter waitany for %lu comms", xbt_dynar_length(&comms));
+ int i = simcall_comm_waitany(&comms, -1);
// not MPI_UNDEFINED, as this is a simix return code
if (i != -1) {
std::vector<MPI_Request> accumulates;
int index;
MPI_Status stat;
- MPI_Status *pstat = status == MPI_STATUSES_IGNORE ? MPI_STATUS_IGNORE : &stat;
+ MPI_Status *pstat = (status == MPI_STATUSES_IGNORE ? MPI_STATUS_IGNORE : &stat);
int retvalue = MPI_SUCCESS;
//tag invalid requests in the set
if (status != MPI_STATUSES_IGNORE) {
wait(&requests[c],pstat);
index = c;
} else {
- index = waitany(count, requests, pstat);
+ index = waitany(count, (MPI_Request*)requests, pstat);
if (index == MPI_UNDEFINED)
break;