001/* 002 * $Id: GBDistHybrid.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 GroebnerBaseDistributedHybridEC 021 */ 022@Deprecated 023public class GBDistHybrid<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 * Number of threads per node to use. 040 */ 041 protected final int threadsPerNode; 042 043 044 /** 045 * Server port to use. 046 */ 047 protected final int port; 048 049 050 /** 051 * GB algorithm to use. 052 */ 053 private final GroebnerBaseDistributedHybrid<C> bbd; 054 055 056 /** 057 * Distributed thread pool to use. 058 */ 059 private final DistThreadPool dtp; 060 061 062 /** 063 * Constructor. 064 * @param threads number of threads respectivly processes. 065 * @param threadsPerNode number of threads per node to use. 066 * @param mfile name of the machine file. 067 * @param port for GB server. 068 */ 069 public GBDistHybrid(int threads, int threadsPerNode, String mfile, int port) { 070 this(threads, threadsPerNode, new OrderedPairlist<C>(), mfile, port); 071 } 072 073 074 /** 075 * Constructor. 076 * @param threads number of threads respectivly processes. 077 * @param threadsPerNode number of threads per node to use. 078 * @param pl pair selection strategy 079 * @param mfile name of the machine file. 080 * @param port for GB server. 081 */ 082 public GBDistHybrid(int threads, int threadsPerNode, PairList<C> pl, String mfile, int port) { 083 this.threads = threads; 084 this.threadsPerNode = threadsPerNode; 085 if (mfile == null || mfile.length() == 0) { 086 this.mfile = "../util/machines"; 087 } else { 088 this.mfile = mfile; 089 } 090 this.port = port; 091 bbd = new GroebnerBaseDistributedHybrid<C>(threads, threadsPerNode, pl, this.port); 092 dtp = new DistThreadPool(threads, this.mfile); // findbugs 093 } 094 095 096 /** 097 * Execute a distributed GB example. Distribute clients and start master. 098 * @param F list of polynomials 099 * @return GB(F) a Groebner base for F. 100 */ 101 public List<GenPolynomial<C>> execute(List<GenPolynomial<C>> F) { 102 String master = dtp.getEC().getMasterHost(); 103 int port = dtp.getEC().getMasterPort(); 104 GBClientHybrid<C> gbc = new GBClientHybrid<C>(threadsPerNode, master, port); 105 for (int i = 0; i < threads; i++) { 106 // schedule remote clients 107 dtp.addJob(gbc); 108 } 109 // run master 110 List<GenPolynomial<C>> G = bbd.GB(F); 111 return G; 112 } 113 114 115 /** 116 * Terminates the distributed thread pools. 117 * @param shutDown true, if shut-down of the remote executable servers is 118 * requested, false, if remote executable servers stay alive. 119 */ 120 public void terminate(boolean shutDown) { 121 bbd.terminate(); 122 dtp.terminate(shutDown); 123 } 124 125} 126 127 128/** 129 * Objects of this class are to be send to a ExecutableServer. 130 */ 131 132class GBClientHybrid<C extends RingElem<C>> implements RemoteExecutable { 133 134 135 String host; 136 137 int port; 138 139 //int threads; 140 141 int threadsPerNode; 142 143 144 /** 145 * GBClientHybrid. 146 * @param threadsPerNode 147 * @param host master 148 * @param port 149 */ 150 public GBClientHybrid(int threadsPerNode, String host, int port) { 151 //this.threads = threads; 152 this.threadsPerNode = threadsPerNode; 153 this.host = host; 154 this.port = port; 155 } 156 157 158 /** Get the String representation. 159 * @see java.lang.Object#toString() 160 */ 161 @Override 162 public String toString() { 163 return "GBClientHybrid(" + threadsPerNode + ", " + host + ":" + port + " )"; 164 } 165 166 167 /** 168 * run. 169 */ 170 public void run() { 171 GroebnerBaseDistributedHybrid<C> bbd; 172 bbd = new GroebnerBaseDistributedHybrid<C>(1, threadsPerNode, null, null, port); 173 try { 174 bbd.clientPart(host); 175 } catch (IOException e) { 176 System.out.println("clientPart, exception " + e); 177 } catch (Exception e) { 178 System.out.println("clientPart, exception " + e); 179 } 180 bbd.terminate(); 181 } 182 183}