LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-01-2018, 02:38 PM   #1
zv6661
LQ Newbie
 
Registered: Jan 2018
Posts: 1

Rep: Reputation: Disabled
Simple Token Ring demonstration using PVM


Hello,

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.

Thanks.

Last edited by zv6661; 02-01-2018 at 07:42 PM.
 
Old 05-10-2018, 06:33 AM   #2
terencemall
LQ Newbie
 
Registered: May 2018
Location: Lynchburg
Posts: 11

Rep: Reputation: Disabled
Quote:
Originally Posted by zv6661 View Post
Hello,

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
 
Old 05-10-2018, 06:49 AM   #3
terencemall
LQ Newbie
 
Registered: May 2018
Location: Lynchburg
Posts: 11

Rep: Reputation: Disabled
Hi
I'd better start with PVM on Parallel and then look for more.
 
Old 05-10-2018, 06:50 AM   #4
terencemall
LQ Newbie
 
Registered: May 2018
Location: Lynchburg
Posts: 11

Rep: Reputation: Disabled
Quote:
Originally Posted by zv6661 View Post
Hello,

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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
token ring - how ? blish_blash Linux - Networking 1 08-17-2005 01:41 PM
Token Ring on Fedora moitessier Fedora 1 08-11-2004 11:02 PM
Linux + Token Ring Half_Elf Linux - Networking 4 09-25-2003 08:34 AM
token ring support celtic32 Linux - Networking 0 08-26-2002 06:44 AM
Token Ring Drivers juniorone Linux - Newbie 3 02-08-2002 03:21 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration