ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm new in the forum. Also I'm beginner in distributed systems. There are not much examples about PVM on the Internet. I have been searching for help for a while.
I have one master and three slave virtual machines. So I have 4 nodes in my internal network. I compile both master.c and slave.c files and run pvm in master node.
Here the master.c
Code:
#include "def.h"
int main() {
int tids[NTASK];
Token *token, tokenobj;
token = &tokenobj;
pvm_spawn(SLAVENAME, NULL, PvmTaskDefault, "", NTASK, tids);
token->number=0; //token content
token->succ=tids[0]; //successor(neighbor), initially process 0
pvm_initsend(PvmDataDefault); //to clear send buffer
pvm_pkint(tids, NTASK, 1); // to pack integer to given task id
pvm_mcast(tids, NTASK, MSG_MST); // to multicast the message
pvm_initsend(PvmDataDefault);
pvm_pkint(&token->number, 1, 1); //to pack the token content
pvm_send(token->succ, MSG_SLV); //to
pvm_recv(-1, MSG_SLV); //to receive message from the last slave
pvm_upkint(&token->number, 1, 1); //to unpack token content
printf("Master: token %d has circulated the ring\n", token->number);
pvm_exit();
return 0;
}
Here the slave.c
Code:
#include "def.h"
int main() {
int i;
Token *token, tokenobj;
token= &tokenobj;
token->succ = 0;
int tid = pvm_mytid();
int tids[NTASK];
//this part is to define the successor nodes
pvm_recv(-1, MSG_MST); //to receive message from master
pvm_upkint(tids, NTASK, 1);
for (i = 0; i < NTASK-1; i++){
if (tids[i] == tid) {
token->succ = tids[i+1];
break;
}
}
if(!token->succ) //successor of the last process is master
token->succ=pvm_parent();
printf("Slave t%x, Successor TID: t%x\n", tid, token->succ);
pvm_recv(-1, MSG_SLV);
pvm_upkint(&token->number, 1, 1);
printf("Slave t%x: Number %d is received\n", tid, token->number);
token->number++; //update the token content
pvm_initsend(PvmDataDefault);
pvm_pkint(&token->number, 1, 1);
pvm_send(token->succ, MSG_SLV);
pvm_exit();
return 0;
}
SS of the output: https://imgur.com/4AmO8rP
So it works, however each node just receives the token, changes it, and sends it to the next node. That means each node is using the token, each slave process is in its critical section.
What about a process does not want to enter its critical section? In other words, a process does not want to use the token? Assume that, P1 is not interested in using the token. Therefore, it receives the token from P0 and directly sends the token to P2 without using it.
How should I implement this? If I used an if block to check processes which want to use the token, would I do it in correct way? Am I the one who decides which process wants to enter its critical section? If so, how real-world token ring examples work? Are the users not able to decide whether they want to use a resource in distributed systems? I'm extremely confused. I can write the code but I don't understand the how it works in real cases.
I'm new in the forum. Also I'm beginner in distributed systems. There are not much examples about PVM on the Internet. I have been searching for help for a while.
I have one master and three slave virtual machines. So I have 4 nodes in my internal network. I compile both master.c and slave.c files and run pvm in master node.
Here the master.c
Code:
#include "def.h"
int main() {
int tids[NTASK];
Token *token, tokenobj;
token = &tokenobj;
pvm_spawn(SLAVENAME, NULL, PvmTaskDefault, "", NTASK, tids);
token->number=0; //token content
token->succ=tids[0]; //successor(neighbor), initially process 0
pvm_initsend(PvmDataDefault); //to clear send buffer
pvm_pkint(tids, NTASK, 1); // to pack integer to given task id
pvm_mcast(tids, NTASK, MSG_MST); // to multicast the message
pvm_initsend(PvmDataDefault);
pvm_pkint(&token->number, 1, 1); //to pack the token content
pvm_send(token->succ, MSG_SLV); //to
pvm_recv(-1, MSG_SLV); //to receive message from the last slave
pvm_upkint(&token->number, 1, 1); //to unpack token content
printf("Master: token %d has circulated the ring\n", token->number);
pvm_exit();
return 0;
}
Here the slave.c
Code:
#include "def.h"
int main() {
int i;
Token *token, tokenobj;
token= &tokenobj;
token->succ = 0;
int tid = pvm_mytid();
int tids[NTASK];
//this part is to define the successor nodes
pvm_recv(-1, MSG_MST); //to receive message from master
pvm_upkint(tids, NTASK, 1);
for (i = 0; i < NTASK-1; i++){
if (tids[i] == tid) {
token->succ = tids[i+1];
break;
}
}
if(!token->succ) //successor of the last process is master
token->succ=pvm_parent();
printf("Slave t%x, Successor TID: t%x\n", tid, token->succ);
pvm_recv(-1, MSG_SLV);
pvm_upkint(&token->number, 1, 1);
printf("Slave t%x: Number %d is received\n", tid, token->number);
token->number++; //update the token content
pvm_initsend(PvmDataDefault);
pvm_pkint(&token->number, 1, 1);
pvm_send(token->succ, MSG_SLV);
pvm_exit();
return 0;
}
SS of the output: https://imgur.com/4AmO8rP like this
So it works, however each node just receives the token, changes it, and sends it to the next node. That means each node is using the token, each slave process is in its critical section.
What about a process does not want to enter its critical section? In other words, a process does not want to use the token? Assume that, P1 is not interested in using the token. Therefore, it receives the token from P0 and directly sends the token to P2 without using it.
How should I implement this? If I used an if block to check processes which want to use the token, would I do it in correct way? Am I the one who decides which process wants to enter its critical section? If so, how real-world token ring examples work? Are the users not able to decide whether they want to use a resource in distributed systems? I'm extremely confused. I can write the code but I don't understand the how it works in real cases.
Thanks.
Hi
I'd better start with http://parallel.vub.ac.be/documentation/pvm/ and then look for more. Perhaps, you should stick to either master.c or slave.c and then see what it gives in the end.
Cheers,
Terence
Facebook - terence.mallett.96
I'm new in the forum. Also I'm beginner in distributed systems. There are not much examples about PVM on the Internet. I have been searching for help for a while.
I have one master and three slave virtual machines. So I have 4 nodes in my internal network. I compile both master.c and slave.c files and run pvm in master node.
Here the master.c
Code:
#include "def.h"
int main() {
int tids[NTASK];
Token *token, tokenobj;
token = &tokenobj;
pvm_spawn(SLAVENAME, NULL, PvmTaskDefault, "", NTASK, tids);
token->number=0; //token content
token->succ=tids[0]; //successor(neighbor), initially process 0
pvm_initsend(PvmDataDefault); //to clear send buffer
pvm_pkint(tids, NTASK, 1); // to pack integer to given task id
pvm_mcast(tids, NTASK, MSG_MST); // to multicast the message
pvm_initsend(PvmDataDefault);
pvm_pkint(&token->number, 1, 1); //to pack the token content
pvm_send(token->succ, MSG_SLV); //to
pvm_recv(-1, MSG_SLV); //to receive message from the last slave
pvm_upkint(&token->number, 1, 1); //to unpack token content
printf("Master: token %d has circulated the ring\n", token->number);
pvm_exit();
return 0;
}
Here the slave.c
Code:
#include "def.h"
int main() {
int i;
Token *token, tokenobj;
token= &tokenobj;
token->succ = 0;
int tid = pvm_mytid();
int tids[NTASK];
//this part is to define the successor nodes
pvm_recv(-1, MSG_MST); //to receive message from master
pvm_upkint(tids, NTASK, 1);
for (i = 0; i < NTASK-1; i++){
if (tids[i] == tid) {
token->succ = tids[i+1];
break;
}
}
if(!token->succ) //successor of the last process is master
token->succ=pvm_parent();
printf("Slave t%x, Successor TID: t%x\n", tid, token->succ);
pvm_recv(-1, MSG_SLV);
pvm_upkint(&token->number, 1, 1);
printf("Slave t%x: Number %d is received\n", tid, token->number);
token->number++; //update the token content
pvm_initsend(PvmDataDefault);
pvm_pkint(&token->number, 1, 1);
pvm_send(token->succ, MSG_SLV);
pvm_exit();
return 0;
}
SS of the output: https://imgur.com/4AmO8rP over here
So it works, however each node just receives the token, changes it, and sends it to the next node. That means each node is using the token, each slave process is in its critical section.
What about a process does not want to enter its critical section? In other words, a process does not want to use the token? Assume that, P1 is not interested in using the token. Therefore, it receives the token from P0 and directly sends the token to P2 without using it.
How should I implement this? If I used an if block to check processes which want to use the token, would I do it in correct way? Am I the one who decides which process wants to enter its critical section? If so, how real-world token ring examples work? Are the users not able to decide whether they want to use a resource in distributed systems? I'm extremely confused. I can write the code but I don't understand the how it works in real cases.
Thanks.
Perhaps, you should stick to either master.c or slave.c and then see what it gives in the end.Facebook - terence.mallett.96
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.