#!/usr/local/bin/clisp ; ; This program will use the grid to multiply 2 numbers which ; are input by the user. It will display the result and the IP ; address of the CPU Resource Server that was used. It will ; also tell the user if the program was self executed or grid ; executed. Portable tasks are self executed if the local ; machine has the highest ACR. ; ; You can run this program directly from the Linux/BSD shell ; prompt, but first set permission to executable. eg: ; ; 1.) Login as "grid" ; 2.) Set permission: "chmod 755 example3.lisp" ; 3.) Run: "./example3.lisp" ; ; ; Simple Grid Protocol 1.02 - Copyright (c) Brendan Kosowski 2004, 2005 ; ; Porta Function makes a programming task portable and sends it ; to the grid for execution on the machine with the highest ACR. ; Task will be self executed if local machine has highest ACR. ; Returned values: ; 1: Result of portable task execution ; 2: IP Address of machine that executed portable task ; 3: T (if self executed) or NIL (if grid executed) ; (defun porta (task) (setq fr (open "/home/grid/token.dat" :direction :input)) (setq token (read-line fr)) (close fr) (setq fr (open "/home/grid/track_ip.dat" :direction :input)) (setq track_ip (read-line fr)) (close fr) (setq fr (open "/home/grid/my_ip.dat" :direction :input)) (setq my_ip (read-line fr)) (close fr) (setq stm (socket:socket-connect 17667 track_ip)) (loop (setq lin (read-line stm)) (when (search "Grid" lin) (return)) ) (setq lin (read-line stm)) (when (string= lin "token?") (format stm "~a~%" token) ) (setq lin (read-line stm)) (when (string= lin "what?") (format stm "show~%") ) (setq grid (read-from-string (read-line stm))) (setq lin (read-line stm)) (when (string= lin "what?") (format stm "bye~%") ) (close stm) (setq stm nil) (setq self nil) (loop (setq best_ip (first (pop grid))) (if (string= my_ip best_ip) (setq self t) (ignore-errors (setq stm (socket:socket-connect 17666 best_ip))) ) (when stm (return)) (when self (return)) ) (if self (setq result (eval task)) (progn (loop (setq lin (read-line stm)) (when (search "Grid" lin) (return)) ) (setq lin (read-line stm)) (when (string= lin "token?") (format stm "~a~%" token) ) (setq lin (read-line stm)) (when (string= lin "what?") (format stm "eval~%") ) (setq lin (read-line stm)) (when (string= lin "code?") (prin1 task stm) (format stm "~%") ) (setq result (read-from-string (read-line stm))) (setq lin (read-line stm)) (when (string= lin "what?") (format stm "bye~%") ) (close stm) ) ) (values result best_ip self) ) ; ; Main Program ; (format t "~%Grid Demo. Performs multiplication & shows which CPU Resource Server was used.~%~%") (format t "Input 1st integer: ") (setq x (read)) (format t "Input 2nd integer: ") (setq y (read)) (multiple-value-setq (result ip self) (porta (list 'progn ; This progn is used to transfer vars to the portable task. (list 'setq 'x x) (list 'setq 'y y) '(progn ; This progn contains the portable task. Not really needed (* x y) ; for this example but good if the portable task contains ) ; multiple forms or objects. ) ) ) (format t "Result of multiplication = ~a~%" result) (format t "CPU Resource Server used = ~a~%" ip) (if self (format t "Task was self executed.~%") (format t "Task was grid executed.~%") ) ; ; End Main ;