crpvm.red 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. %**********************************************************************
  2. module crackpvm$
  3. %**********************************************************************
  4. % Procedures to support parallel computing on PVM
  5. % Authors: Thomas Wolf and Winfried Neun 2002
  6. symbolic procedure pvm_activate$
  7. if getd('pvm_mytid) then <<pvm_able:=t;current_dir:=pwd()>>
  8. else <<pvm_able:=nil;current_dir:=nil>>$
  9. symbolic procedure pvm_active$
  10. if pvm_able then t else <<
  11. terpri()$write"PVM is either not active on this computer"$
  12. terpri()$write"or interactively switched off. Try 'ep'."$
  13. terpri()$
  14. nil
  15. >>$
  16. symbolic procedure pvm_try$
  17. if pvm_able and (read_proczaehler()<24) then t
  18. else nil$
  19. %symbolic procedure inc_session$
  20. %begin scalar sess$
  21. % setq(sess,bldmsg("%w%w",session_,"processes"));
  22. % lock sess;
  23. % in sess;
  24. % backup_:=add1 backup_;
  25. % out sess;
  26. % write "off echo$backup_:=",backup_,"$ end$"$
  27. % terpri()$
  28. % shut sess;
  29. % unlock sess;
  30. %end$
  31. symbolic procedure read_proczaehler$
  32. begin scalar zae,zaef$
  33. zaef:=open("/home/twolf/zaehler",'input);
  34. zae:=channelread(zaef);
  35. close(zaef);
  36. return zae
  37. end$
  38. symbolic procedure add_process(processes,pdes,forg)$
  39. begin scalar s,ss,h$
  40. %----- passing on the current status
  41. ss:=level_string(session_)$
  42. setq(h,bldmsg("%w%w%w",current_dir,ss,"tmp"));
  43. backup_to_file(pdes,forg,h);
  44. !*iconic:=nil$ %t; %not !*batch_mode;
  45. % =t --> only an icon opens, =nil --> a window opens
  46. %----- start new process
  47. s:=remote_process("");
  48. processes:=cons(s,processes);
  49. %----- update the counting of processes
  50. system "/home/twolf/proczaehler plus"$
  51. %----- print the new level
  52. remote_write(s,{'list,"Process id: ",s," level: ",ss});
  53. terpri()$write"A process with id no ",s," has been started."$
  54. %----- change directory
  55. remote_call!*(s,'cd,{current_dir},0)$
  56. %----- load crack
  57. remote_call!*(s,'load_package,{{"~/red/src5/crack"}},0)$
  58. %----- specify what crack should load (and do)
  59. remote_call!*(s,'set,{'old_history,{'rb,h}},0);
  60. %----- start Crack
  61. remote_call(s,'crackshell,{'list},0)$
  62. %----- if interactive then not instant closure of window
  63. %----- when computation is finished to inspect the result
  64. %----- so wait for 1000 sec.
  65. if null !*iconic then remote_call!*(s,'system,{"sleep 1000"},0);
  66. %----- close the REDUCE session when crackshell() finished
  67. remote_call!*(s,'system,{"/home/twolf/proczaehler minus"},0)$
  68. remote_call!*(s,'system,{bldmsg("%w%w","rm ",h)},0)$
  69. remote_call!*(s,'exitlisp,{'list},0)$
  70. return processes
  71. end$
  72. symbolic procedure drop_process(processes)$
  73. begin scalar s$
  74. terpri()$write"The following processes are active: "$
  75. listprint(processes)$
  76. terpri()$write"To kill ALL remote processes that have been"$
  77. terpri()$write"generated by this process enter -1,"$
  78. terpri()$write"to kill a single process enter its process id: "$
  79. promptstring!*:=""$
  80. s:=termread()$
  81. if s=-1 then <<
  82. processes:=nil;
  83. system "/home/twolf/proczaehler init"
  84. >> else <<
  85. delete(s,processes);
  86. system "/home/twolf/proczaehler minus"
  87. >>$
  88. remote_kill(s);
  89. return processes
  90. end$
  91. symbolic procedure remote_crackmain(pdes,forg)$
  92. begin scalar h,s,ss;
  93. %BUG? Some global variables have to be passed on even if they
  94. %should not be read when returning!?
  95. %----- passing on the current status
  96. ss:=level_string(session_)$
  97. setq(h,bldmsg("%w%w%w",current_dir,ss,"tmp"));
  98. backup_to_file(pdes,forg,h);
  99. % !*iconic:=nil$ %t; %not !*batch_mode;
  100. % =t --> only an icon opens, =nil --> a window opens
  101. %----- start new process
  102. s:=remote_process("");
  103. %----- update the counting of processes
  104. system "/home/twolf/proczaehler plus"$
  105. %----- print the new level
  106. remote_write(s,{'list,"Process id: ",s," level: ",ss});
  107. %----- change directory
  108. remote_call!*(s,'cd,{current_dir},0)$
  109. %----- load crack
  110. remote_call!*(s,'load_package,{{"~/red/src5/crack"}},0)$
  111. %----- specify what crack should load (and do)
  112. remote_call!*(s,'set,{'old_history,{'rb,h}},0);
  113. %----- start Crack
  114. remote_call(s,'crackshell,{'list},0)$
  115. %----- if interactive then not instant closure of window
  116. %----- when computation is finished to inspect the result
  117. %----- so wait for 1000 sec.
  118. if null !*iconic then remote_call!*(s,'system,{"sleep 1000"},0);
  119. %----- close the REDUCE session when crackshell() finished
  120. remote_call!*(s,'system,{"/home/twolf/proczaehler minus"},0)$
  121. remote_call!*(s,'system,{bldmsg("%w%w","rm ",h)},0)$
  122. remote_call!*(s,'exitlisp,{},0)$
  123. %----- changes done at the end of crackmain(), e.g. delete property lists
  124. level_:=cdr level_;
  125. for each s in pdes do drop_pde(s,pdes,nil)$
  126. for each s in forg do
  127. if pairp s then setprop(cadr s,nil)
  128. else setprop( s,nil)$
  129. end$
  130. endmodule$
  131. end$