navigation

MPWN
iteration
chaos
pvm
3d openGL
pov-ray

xyang@tjhsst.edu

pvm - parellel virtual machines

parallel virtual machines (pvm) is a strategy used in the unix environment to speed up processes by dividing them among different machines. there are several different appraoches to pvm. here are some:

master-slave
in pvm, there can be a master, where the master program is running, and a slave, where the processes can be sent. in the master-slave approach, there is one master that sends out specific data to other machines (slaves), and each slave returns something to the master.
multi-casting
this is the same thing as master-slave except the same data is sent to all slaves, and it is up to each slave to determine what it is to calculate and return.
relay
the relay (or "pipeline") approach is just what it sounds like. data is sent to a slave from the master, and the slaves each also send data to another slave until a terminating condition. this is very important because if there is none, then the processes keep running without stopping, which is not very healthy.
tree
a tree originates with one node. this node divides what it has to do, and sends different portions of them to other nodes that do the same thing. when the diagram is drawn out, the map of the nodes look like a tree. although the most common, the binary tree approach (where each node points to two other nodes) is not the only algorithm. the tree is recursive, and MUST have a terminating condition. this is even MORE important because if there is not one, processes will keep mounting up at an exponential scale, which is extremely hazardous to your health.
cluster
a cluster is similar to a tree in that it involves many different machines and nodes, but instead of manually calculating what to send each node, the program is copied and forks the processes.

my pvm program

my program uses the master-slave approach. the master asks for user input and generates that many tasks. each slave is sent an integer 0 thru the number of total tasks. upon receiving the integer, the slave calculates the square and the square root of that integer. the next part involves accessing the dictionary (/usr/dict/words) on each machine. each slaves opens the file of words and picks out the word that corresponds to the square of the integer it was sent. for example, if a slave is sent 6, it would pick out the 36th word of the list.

since the dictionary contains only 45402 words, and the square of the integer might be larger than that, i made it so that it cycles around. in other words, the num MOD 45402th word is taken. the slave stores the square root, the square, and the word in variables and sends them back to the master.

before receiving any data from the slaves, the master constructs an array of structs the size of the number of tasks. the struct has several parameters: original number, square root, square, and the dictionary word. data is then received from each of the slaves and placed into the array. the next step is sorting the structs in the array by the bubble sort, by far the most infamous algorithm for speed (!). in retrospect, it would have been much easier to just place each package sent by the slaves into the corresponding spot in the array...

the final step is displaying everything. this is done successfully, and some windowshots can be seen below.


full-size
this simply demonstrates a regular run of the program.

full-size
this also demonstrates another run. however, the max was selected so that square would exceed 45042. as can be seen, the words cycle around so that each integer is associated with a word.

last but not least, here is the code for my wonderful program.

mymaster.cpp
myslave.cpp

last updated april 11, 2002.