001/* 002 * $Id: GBDist.java 4334 2012-12-28 11:49:57Z kredel $ 003 */ 004 005package edu.jas.gb; 006 007 008import java.io.IOException; 009import java.util.List; 010 011import edu.jas.poly.GenPolynomial; 012import edu.jas.structure.RingElem; 013import edu.jas.util.DistThreadPool; 014import edu.jas.util.RemoteExecutable; 015 016 017/** 018 * Setup to run a distributed GB example. 019 * @author Heinz Kredel 020 * @deprecated use GroebnerBaseDistributedEC 021 */ 022@Deprecated 023public class GBDist<C extends RingElem<C>> { 024 025 026 /** 027 * machine file to use. 028 */ 029 private final String mfile; 030 031 032 /** 033 * Number of threads to use. 034 */ 035 protected final int threads; 036 037 038 /** 039 * Server port to use. 040 */ 041 protected final int port; 042 043 044 /** 045 * GB algorithm to use. 046 */ 047 private final GroebnerBaseDistributed<C> bbd; 048 049 050 /** 051 * Distributed thread pool to use. 052 */ 053 private final DistThreadPool dtp; 054 055 056 /** 057 * Constructor. 058 * @param threads number of threads respectivly processes. 059 * @param mfile name of the machine file. 060 * @param port for GB server. 061 */ 062 public GBDist(int threads, String mfile, int port) { 063 this(threads, new OrderedPairlist<C>(), mfile, port); 064 } 065 066 067 /** 068 * Constructor. 069 * @param threads number of threads respectivly processes. 070 * @param pl pair selection strategy 071 * @param mfile name of the machine file. 072 * @param port for GB server. 073 */ 074 public GBDist(int threads, PairList<C> pl, String mfile, int port) { 075 this.threads = threads; 076 if (mfile == null || mfile.length() == 0) { 077 this.mfile = "../util/machines"; 078 } else { 079 this.mfile = mfile; 080 } 081 this.port = port; 082 bbd = new GroebnerBaseDistributed<C>(threads, pl, this.port); 083 dtp = new DistThreadPool(threads, this.mfile); // findbugs 084 } 085 086 087 /** 088 * Execute a distributed GB example. Distribute clients and start master. 089 * @param F list of polynomials 090 * @return GB(F) a Groebner base for F. 091 */ 092 public List<GenPolynomial<C>> execute(List<GenPolynomial<C>> F) { 093 String master = dtp.getEC().getMasterHost(); 094 int port = dtp.getEC().getMasterPort(); 095 GBClient<C> gbc = new GBClient<C>(master, port); 096 for (int i = 0; i < threads; i++) { 097 // schedule remote clients 098 dtp.addJob(gbc); 099 } 100 // run master 101 List<GenPolynomial<C>> G = bbd.GB(F); 102 return G; 103 } 104 105 106 /** 107 * Terminates the distributed thread pools. 108 * @param shutDown true, if shut-down of the remote executable servers is 109 * requested, false, if remote executable servers stay alive. 110 */ 111 public void terminate(boolean shutDown) { 112 bbd.terminate(); 113 dtp.terminate(shutDown); 114 } 115 116} 117 118 119/** 120 * Objects of this class are to be send to a ExecutableServer. 121 */ 122 123class GBClient<C extends RingElem<C>> implements RemoteExecutable { 124 125 126 String host; 127 128 129 int port; 130 131 132 /** 133 * GBClient. 134 * @param host 135 * @param port 136 */ 137 public GBClient(String host, int port) { 138 this.host = host; 139 this.port = port; 140 } 141 142 143 /** 144 * run. 145 */ 146 public void run() { 147 GroebnerBaseDistributed<C> bbd; 148 bbd = new GroebnerBaseDistributed<C>(1, null, null, port); 149 try { 150 bbd.clientPart(host); 151 } catch (IOException ignored) { 152 } 153 bbd.terminate(); 154 } 155 156}