Roma  Karageorgievich Roma Karageorgievich - 6 months ago 45
Java Question

SimGrid. Simultaneous receiving two tasks

There is declaring of host's features in platform.xml file:

<host id="Tier1_1" core="2" speed="100f"/>


The
worker
process lives in this host.
How can worker simultaneously receive and execute two tasks (in case of number of core is 2)?
Now I use such code, but it doesn't work in this case(this code can't simultaneously receive two task, only one);

while(true) {
commReceived = Task.irecv("Tier1_" + num);
commReceived.waitCompletion();
if (commReceived.test()){
task = commReceived.getTask();
commReceived = null;
Msg.info("Receive " + task.getName());
task.execute();
Msg.info("End to execute " + task.getName());
}


UPD:

Now I use this simplified code. I send to this mailbox ("Tier1_2"). But task can't reach it:

public void main(String[] args) throws MsgException {
for (int j=0; j<2; j++){
Process process = new Process(getHost().getName(), "Tier1_2_" + j) {
@Override
public void main(String[] strings) throws MsgException {
while (true){
task = Task.receive("Tier1_2");
}
}
};process.start();
}
}


But it gives:

[105.412371] /builds/workspace/SimGrid-Multi/build_mode/Debug/node/simgrid-ubuntu-trusty-64/build/SimGrid-3.13/src/simix/smx_global.cpp:554: [simix_kernel/CRITICAL] Oops ! Deadlock or code not perfectly clean.


How correctly I should declare process?

Answer

The idea is to have the worker process to spawn other processes that listen on different mailboxes. For instance something like (which I haven't tested)

for (int i = 0; i < 2; i++) {
    Process p = new Process(getHost.getName(), "Tier1_" + i) {
        public void main(String[] args) throws MsgException {
        String mailbox = getName();
        while(true) {
          commReceived = Task.irecv(mailbox);
          commReceived.waitCompletion();
          if (commReceived.test()){
            task = commReceived.getTask();
            commReceived = null;
            Msg.info("Receive " + task.getName());
            task.execute();
            Msg.info("End to execute " + task.getName());
          }
        }
      });
      p.start();
}

The new Process() method takes two arguments: the name of the host on which the process runs, and the name of the process itself. Here we declare a unique process name that will be used as the mailbox name (hence the mailbox = getName()).

Don't forget to kill these processes at some point, as they run forever. So you might want to put all the spawned processes in a vector to ease that.

Comments