001/* 002 * $Id: SGCDParallelProxy.java 5502 2016-05-12 21:58:10Z kredel $ 003 */ 004 005package edu.jas.fd; 006 007 008import java.util.ArrayList; 009import java.util.List; 010import java.util.concurrent.Callable; 011import java.util.concurrent.ExecutionException; 012import java.util.concurrent.ExecutorService; 013import java.util.concurrent.TimeoutException; 014 015import org.apache.log4j.Logger; 016 017import edu.jas.kern.ComputerThreads; 018import edu.jas.kern.PreemptingException; 019import edu.jas.poly.GenPolynomial; 020import edu.jas.poly.GenSolvablePolynomial; 021import edu.jas.structure.GcdRingElem; 022import edu.jas.structure.RingFactory; 023 024 025/** 026 * Solvable greatest common divisor parallel proxy. Executes methods from two 027 * implementations in parallel and returns the result from the fastest run. Uses 028 * timeout on <code>invokeAny()</code> and return fake common divisor <it>1</it> 029 * in case of timeout. 030 * @author Heinz Kredel 031 */ 032 033public class SGCDParallelProxy<C extends GcdRingElem<C>> extends GreatestCommonDivisorAbstract<C> { 034 035 036 private static final Logger logger = Logger.getLogger(SGCDParallelProxy.class); 037 038 039 private static final boolean debug = logger.isDebugEnabled(); //logger.isInfoEnabled(); 040 041 042 /** 043 * GCD engines. 044 */ 045 public final GreatestCommonDivisorAbstract<C> e0; 046 047 048 public final GreatestCommonDivisorAbstract<C> e1; 049 050 051 public final GreatestCommonDivisorAbstract<C> e2; 052 053 054 /** 055 * Thread pool. 056 */ 057 protected transient ExecutorService pool; 058 059 060 /** 061 * ParallelProxy constructor. 062 * @param cf coefficient ring. 063 */ 064 public SGCDParallelProxy(RingFactory<C> cf, GreatestCommonDivisorAbstract<C> e1, 065 GreatestCommonDivisorAbstract<C> e2) { 066 super(cf); 067 this.e0 = new GreatestCommonDivisorFake<C>(cf); 068 this.e1 = e1; 069 this.e2 = e2; 070 pool = ComputerThreads.getPool(); 071 //System.out.println("pool 2 = "+pool); 072 } 073 074 075 /** 076 * Get the String representation with gcd engines. 077 * @see java.lang.Object#toString() 078 */ 079 @Override 080 public String toString() { 081 return "SGCDParallelProxy[ " + e1.getClass().getName() + ", " + e2.getClass().getName() + " ]"; 082 } 083 084 085 /** 086 * Left univariate GenSolvablePolynomial greatest common divisor. 087 * @param P univariate GenSolvablePolynomial. 088 * @param S univariate GenSolvablePolynomial. 089 * @return gcd(P,S). 090 */ 091 @Override 092 public GenSolvablePolynomial<C> leftBaseGcd(final GenSolvablePolynomial<C> P, 093 final GenSolvablePolynomial<C> S) { 094 if (debug) { 095 if (ComputerThreads.NO_THREADS) { 096 throw new RuntimeException("this should not happen"); 097 } 098 } 099 if (S == null || S.isZERO()) { 100 return P; 101 } 102 if (P == null || P.isZERO()) { 103 return S; 104 } 105 // parallel case 106 GenSolvablePolynomial<C> g = P.ring.getONE(); 107 //Callable<GenSolvablePolynomial<C>> c0; 108 //Callable<GenSolvablePolynomial<C>> c1; 109 List<Callable<GenSolvablePolynomial<C>>> cs = new ArrayList<Callable<GenSolvablePolynomial<C>>>(2); 110 cs.add(new Callable<GenSolvablePolynomial<C>>() { 111 112 113 public GenSolvablePolynomial<C> call() { 114 try { 115 //System.out.println("starting e1 " + e1.getClass().getName()); 116 GenSolvablePolynomial<C> g = e1.leftBaseGcd(P, S); 117 if (debug) { 118 logger.info("SGCDParallelProxy done e1 " + e1.getClass().getName()); 119 } 120 return g; 121 } catch (PreemptingException e) { 122 throw new RuntimeException("SGCDParallelProxy e1 pre " + e); 123 //return P.ring.getONE(); 124 } catch (Exception e) { 125 //e.printStackTrace(); 126 logger.info("SGCDParallelProxy e1 " + e); 127 logger.info("SGCDParallelProxy P = " + P); 128 logger.info("SGCDParallelProxy S = " + S); 129 throw new RuntimeException("SGCDParallelProxy e1 " + e); 130 //return P.ring.getONE(); 131 } 132 } 133 }); 134 cs.add(new Callable<GenSolvablePolynomial<C>>() { 135 136 137 public GenSolvablePolynomial<C> call() { 138 try { 139 //System.out.println("starting e2 " + e2.getClass().getName()); 140 GenSolvablePolynomial<C> g = e2.leftBaseGcd(P, S); 141 if (debug) { 142 logger.info("SGCDParallelProxy done e2 " + e2.getClass().getName()); 143 } 144 return g; 145 } catch (PreemptingException e) { 146 throw new RuntimeException("SGCDParallelProxy e2 pre " + e); 147 //return P.ring.getONE(); 148 } catch (Exception e) { 149 //e.printStackTrace(); 150 logger.info("SGCDParallelProxy e2 " + e); 151 logger.info("SGCDParallelProxy P = " + P); 152 logger.info("SGCDParallelProxy S = " + S); 153 throw new RuntimeException("SGCDParallelProxy e2 " + e); 154 //return P.ring.getONE(); 155 } 156 } 157 }); 158 try { 159 if (ComputerThreads.getTimeout() < 0) { 160 g = pool.invokeAny(cs); 161 } else { 162 g = pool.invokeAny(cs, ComputerThreads.getTimeout(), ComputerThreads.getTimeUnit()); 163 } 164 } catch (InterruptedException ignored) { 165 logger.info("InterruptedException " + ignored); 166 Thread.currentThread().interrupt(); 167 } catch (ExecutionException e) { 168 logger.info("ExecutionException " + e); 169 Thread.currentThread().interrupt(); 170 } catch (TimeoutException e) { 171 logger.info("TimeoutException after " + ComputerThreads.getTimeout() + " " 172 + ComputerThreads.getTimeUnit()); 173 g = e0.leftBaseGcd(P, S); // fake returns 1 174 } 175 return g; 176 } 177 178 179 /** 180 * left univariate GenSolvablePolynomial recursive greatest common divisor. 181 * @param P univariate recursive GenSolvablePolynomial. 182 * @param S univariate recursive GenSolvablePolynomial. 183 * @return gcd(P,S). 184 */ 185 @Override 186 public GenSolvablePolynomial<GenPolynomial<C>> leftRecursiveUnivariateGcd( 187 final GenSolvablePolynomial<GenPolynomial<C>> P, 188 final GenSolvablePolynomial<GenPolynomial<C>> S) { 189 if (debug) { 190 if (ComputerThreads.NO_THREADS) { 191 throw new RuntimeException("this should not happen"); 192 } 193 } 194 if (S == null || S.isZERO()) { 195 return P; 196 } 197 if (P == null || P.isZERO()) { 198 return S; 199 } 200 // parallel case 201 GenSolvablePolynomial<GenPolynomial<C>> g = P.ring.getONE(); 202 //Callable<GenSolvablePolynomial<GenPolynomial<C>>> c0; 203 //Callable<GenSolvablePolynomial<GenPolynomial<C>>> c1; 204 List<Callable<GenSolvablePolynomial<GenPolynomial<C>>>> cs = new ArrayList<Callable<GenSolvablePolynomial<GenPolynomial<C>>>>( 205 2); 206 cs.add(new Callable<GenSolvablePolynomial<GenPolynomial<C>>>() { 207 208 209 public GenSolvablePolynomial<GenPolynomial<C>> call() { 210 try { 211 GenSolvablePolynomial<GenPolynomial<C>> g = e1.leftRecursiveUnivariateGcd(P, S); 212 if (debug) { 213 logger.info("SGCDParallelProxy done e1 " + e1.getClass().getName()); 214 } 215 return g; 216 } catch (PreemptingException e) { 217 throw new RuntimeException("SGCDParallelProxy e1 pre " + e); 218 //return P.ring.getONE(); 219 } catch (Exception e) { 220 //e.printStackTrace(); 221 logger.info("SGCDParallelProxy e1 " + e); 222 logger.info("SGCDParallelProxy P = " + P); 223 logger.info("SGCDParallelProxy S = " + S); 224 throw new RuntimeException("SGCDParallelProxy e1 " + e); 225 //return P.ring.getONE(); 226 } 227 } 228 }); 229 cs.add(new Callable<GenSolvablePolynomial<GenPolynomial<C>>>() { 230 231 232 public GenSolvablePolynomial<GenPolynomial<C>> call() { 233 try { 234 GenSolvablePolynomial<GenPolynomial<C>> g = e2.leftRecursiveUnivariateGcd(P, S); 235 if (debug) { 236 logger.info("SGCDParallelProxy done e2 " + e2.getClass().getName()); 237 } 238 return g; 239 } catch (PreemptingException e) { 240 throw new RuntimeException("SGCDParallelProxy e2 pre " + e); 241 //return P.ring.getONE(); 242 } catch (Exception e) { 243 //e.printStackTrace(); 244 logger.info("SGCDParallelProxy e2 " + e); 245 logger.info("SGCDParallelProxy P = " + P); 246 logger.info("SGCDParallelProxy S = " + S); 247 throw new RuntimeException("SGCDParallelProxy e2 " + e); 248 //return P.ring.getONE(); 249 } 250 } 251 }); 252 try { 253 if (ComputerThreads.getTimeout() < 0) { 254 g = pool.invokeAny(cs); 255 } else { 256 g = pool.invokeAny(cs, ComputerThreads.getTimeout(), ComputerThreads.getTimeUnit()); 257 } 258 } catch (InterruptedException ignored) { 259 logger.info("InterruptedException " + ignored); 260 Thread.currentThread().interrupt(); 261 } catch (ExecutionException e) { 262 logger.info("ExecutionException " + e); 263 Thread.currentThread().interrupt(); 264 } catch (TimeoutException e) { 265 logger.info("TimeoutException after " + ComputerThreads.getTimeout() + " " 266 + ComputerThreads.getTimeUnit()); 267 g = e0.leftRecursiveUnivariateGcd(P, S); // fake returns 1 268 } 269 return g; 270 } 271 272 273 /** 274 * Left GenSolvablePolynomial greatest common divisor. 275 * @param P GenSolvablePolynomial. 276 * @param S GenSolvablePolynomial. 277 * @return leftGcd(P,S). 278 */ 279 @Override 280 public GenSolvablePolynomial<C> leftGcd(final GenSolvablePolynomial<C> P, 281 final GenSolvablePolynomial<C> S) { 282 if (debug) { 283 if (ComputerThreads.NO_THREADS) { 284 throw new RuntimeException("this should not happen"); 285 } 286 } 287 if (S == null || S.isZERO()) { 288 return P; 289 } 290 if (P == null || P.isZERO()) { 291 return S; 292 } 293 // parallel case 294 GenSolvablePolynomial<C> g = P.ring.getONE(); 295 //Callable<GenSolvablePolynomial<C>> c0; 296 //Callable<GenSolvablePolynomial<C>> c1; 297 List<Callable<GenSolvablePolynomial<C>>> cs = new ArrayList<Callable<GenSolvablePolynomial<C>>>(2); 298 cs.add(new Callable<GenSolvablePolynomial<C>>() { 299 300 301 public GenSolvablePolynomial<C> call() { 302 try { 303 //System.out.println("starting e1 " + e1.getClass().getName()); 304 GenSolvablePolynomial<C> g = e1.leftGcd(P, S); 305 if (debug) { 306 logger.info("SGCDParallelProxy done e1 " + e1.getClass().getName()); 307 } 308 return g; 309 } catch (PreemptingException e) { 310 throw new RuntimeException("SGCDParallelProxy e1 pre " + e); 311 //return P.ring.getONE(); 312 } catch (Exception e) { 313 //e.printStackTrace(); 314 logger.info("SGCDParallelProxy e1 " + e); 315 logger.info("SGCDParallelProxy P = " + P); 316 logger.info("SGCDParallelProxy S = " + S); 317 throw new RuntimeException("SGCDParallelProxy e1 " + e); 318 //return P.ring.getONE(); 319 } 320 } 321 }); 322 cs.add(new Callable<GenSolvablePolynomial<C>>() { 323 324 325 public GenSolvablePolynomial<C> call() { 326 try { 327 //System.out.println("starting e2 " + e2.getClass().getName()); 328 GenSolvablePolynomial<C> g = e2.leftGcd(P, S); 329 if (debug) { 330 logger.info("SGCDParallelProxy done e2 " + e2.getClass().getName()); 331 } 332 return g; 333 } catch (PreemptingException e) { 334 throw new RuntimeException("SGCDParallelProxy e2 pre " + e); 335 //return P.ring.getONE(); 336 } catch (Exception e) { 337 //e.printStackTrace(); 338 logger.info("SGCDParallelProxy e2 " + e); 339 logger.info("SGCDParallelProxy P = " + P); 340 logger.info("SGCDParallelProxy S = " + S); 341 throw new RuntimeException("SGCDParallelProxy e2 " + e); 342 //return P.ring.getONE(); 343 } 344 } 345 }); 346 try { 347 if (ComputerThreads.getTimeout() < 0) { 348 g = pool.invokeAny(cs); 349 } else { 350 g = pool.invokeAny(cs, ComputerThreads.getTimeout(), ComputerThreads.getTimeUnit()); 351 } 352 } catch (InterruptedException ignored) { 353 logger.info("InterruptedException " + ignored); 354 Thread.currentThread().interrupt(); 355 } catch (ExecutionException e) { 356 logger.info("ExecutionException " + e); 357 Thread.currentThread().interrupt(); 358 } catch (TimeoutException e) { 359 logger.info("TimeoutException after " + ComputerThreads.getTimeout() + " " 360 + ComputerThreads.getTimeUnit()); 361 g = e0.leftGcd(P, S); // fake returns 1 362 } 363 return g; 364 } 365 366 367 /** 368 * Right univariate GenSolvablePolynomial greatest common divisor. 369 * @param P univariate GenSolvablePolynomial. 370 * @param S univariate GenSolvablePolynomial. 371 * @return gcd(P,S). 372 */ 373 @Override 374 public GenSolvablePolynomial<C> rightBaseGcd(final GenSolvablePolynomial<C> P, 375 final GenSolvablePolynomial<C> S) { 376 if (debug) { 377 if (ComputerThreads.NO_THREADS) { 378 throw new RuntimeException("this should not happen"); 379 } 380 } 381 if (S == null || S.isZERO()) { 382 return P; 383 } 384 if (P == null || P.isZERO()) { 385 return S; 386 } 387 // parallel case 388 GenSolvablePolynomial<C> g = P.ring.getONE(); 389 //Callable<GenSolvablePolynomial<C>> c0; 390 //Callable<GenSolvablePolynomial<C>> c1; 391 List<Callable<GenSolvablePolynomial<C>>> cs = new ArrayList<Callable<GenSolvablePolynomial<C>>>(2); 392 cs.add(new Callable<GenSolvablePolynomial<C>>() { 393 394 395 public GenSolvablePolynomial<C> call() { 396 try { 397 //System.out.println("starting e1 " + e1.getClass().getName()); 398 GenSolvablePolynomial<C> g = e1.rightBaseGcd(P, S); 399 if (debug) { 400 logger.info("SGCDParallelProxy done e1 " + e1.getClass().getName()); 401 } 402 return g; 403 } catch (PreemptingException e) { 404 throw new RuntimeException("SGCDParallelProxy e1 pre " + e); 405 //return P.ring.getONE(); 406 } catch (Exception e) { 407 //e.printStackTrace(); 408 logger.info("SGCDParallelProxy e1 " + e); 409 logger.info("SGCDParallelProxy P = " + P); 410 logger.info("SGCDParallelProxy S = " + S); 411 throw new RuntimeException("SGCDParallelProxy e1 " + e); 412 //return P.ring.getONE(); 413 } 414 } 415 }); 416 cs.add(new Callable<GenSolvablePolynomial<C>>() { 417 418 419 public GenSolvablePolynomial<C> call() { 420 try { 421 //System.out.println("starting e2 " + e2.getClass().getName()); 422 GenSolvablePolynomial<C> g = e2.rightBaseGcd(P, S); 423 if (debug) { 424 logger.info("SGCDParallelProxy done e2 " + e2.getClass().getName()); 425 } 426 return g; 427 } catch (PreemptingException e) { 428 throw new RuntimeException("SGCDParallelProxy e2 pre " + e); 429 //return P.ring.getONE(); 430 } catch (Exception e) { 431 //e.printStackTrace(); 432 logger.info("SGCDParallelProxy e2 " + e); 433 logger.info("SGCDParallelProxy P = " + P); 434 logger.info("SGCDParallelProxy S = " + S); 435 throw new RuntimeException("SGCDParallelProxy e2 " + e); 436 //return P.ring.getONE(); 437 } 438 } 439 }); 440 try { 441 if (ComputerThreads.getTimeout() < 0) { 442 g = pool.invokeAny(cs); 443 } else { 444 g = pool.invokeAny(cs, ComputerThreads.getTimeout(), ComputerThreads.getTimeUnit()); 445 } 446 } catch (InterruptedException ignored) { 447 logger.info("InterruptedException " + ignored); 448 Thread.currentThread().interrupt(); 449 } catch (ExecutionException e) { 450 logger.info("ExecutionException " + e); 451 Thread.currentThread().interrupt(); 452 } catch (TimeoutException e) { 453 logger.info("TimeoutException after " + ComputerThreads.getTimeout() + " " 454 + ComputerThreads.getTimeUnit()); 455 g = e0.rightBaseGcd(P, S); // fake returns 1 456 } 457 return g; 458 } 459 460 461 /** 462 * right univariate GenSolvablePolynomial recursive greatest common divisor. 463 * @param P univariate recursive GenSolvablePolynomial. 464 * @param S univariate recursive GenSolvablePolynomial. 465 * @return gcd(P,S). 466 */ 467 @Override 468 public GenSolvablePolynomial<GenPolynomial<C>> rightRecursiveUnivariateGcd( 469 final GenSolvablePolynomial<GenPolynomial<C>> P, 470 final GenSolvablePolynomial<GenPolynomial<C>> S) { 471 if (debug) { 472 if (ComputerThreads.NO_THREADS) { 473 throw new RuntimeException("this should not happen"); 474 } 475 } 476 if (S == null || S.isZERO()) { 477 return P; 478 } 479 if (P == null || P.isZERO()) { 480 return S; 481 } 482 // parallel case 483 GenSolvablePolynomial<GenPolynomial<C>> g = P.ring.getONE(); 484 //Callable<GenSolvablePolynomial<GenPolynomial<C>>> c0; 485 //Callable<GenSolvablePolynomial<GenPolynomial<C>>> c1; 486 List<Callable<GenSolvablePolynomial<GenPolynomial<C>>>> cs = new ArrayList<Callable<GenSolvablePolynomial<GenPolynomial<C>>>>( 487 2); 488 cs.add(new Callable<GenSolvablePolynomial<GenPolynomial<C>>>() { 489 490 491 public GenSolvablePolynomial<GenPolynomial<C>> call() { 492 try { 493 GenSolvablePolynomial<GenPolynomial<C>> g = e1.rightRecursiveUnivariateGcd(P, S); 494 if (debug) { 495 logger.info("SGCDParallelProxy done e1 " + e1.getClass().getName()); 496 } 497 return g; 498 } catch (PreemptingException e) { 499 throw new RuntimeException("SGCDParallelProxy e1 pre " + e); 500 //return P.ring.getONE(); 501 } catch (Exception e) { 502 //e.printStackTrace(); 503 logger.info("SGCDParallelProxy e1 " + e); 504 logger.info("SGCDParallelProxy P = " + P); 505 logger.info("SGCDParallelProxy S = " + S); 506 throw new RuntimeException("SGCDParallelProxy e1 " + e); 507 //return P.ring.getONE(); 508 } 509 } 510 }); 511 cs.add(new Callable<GenSolvablePolynomial<GenPolynomial<C>>>() { 512 513 514 public GenSolvablePolynomial<GenPolynomial<C>> call() { 515 try { 516 GenSolvablePolynomial<GenPolynomial<C>> g = e2.rightRecursiveUnivariateGcd(P, S); 517 if (debug) { 518 logger.info("SGCDParallelProxy done e2 " + e2.getClass().getName()); 519 } 520 return g; 521 } catch (PreemptingException e) { 522 throw new RuntimeException("SGCDParallelProxy e2 pre " + e); 523 //return P.ring.getONE(); 524 } catch (Exception e) { 525 //e.printStackTrace(); 526 logger.info("SGCDParallelProxy e2 " + e); 527 logger.info("SGCDParallelProxy P = " + P); 528 logger.info("SGCDParallelProxy S = " + S); 529 throw new RuntimeException("SGCDParallelProxy e2 " + e); 530 //return P.ring.getONE(); 531 } 532 } 533 }); 534 try { 535 if (ComputerThreads.getTimeout() < 0) { 536 g = pool.invokeAny(cs); 537 } else { 538 g = pool.invokeAny(cs, ComputerThreads.getTimeout(), ComputerThreads.getTimeUnit()); 539 } 540 } catch (InterruptedException ignored) { 541 logger.info("InterruptedException " + ignored); 542 Thread.currentThread().interrupt(); 543 } catch (ExecutionException e) { 544 logger.info("ExecutionException " + e); 545 Thread.currentThread().interrupt(); 546 } catch (TimeoutException e) { 547 logger.info("TimeoutException after " + ComputerThreads.getTimeout() + " " 548 + ComputerThreads.getTimeUnit()); 549 g = e0.rightRecursiveUnivariateGcd(P, S); // fake returns 1 550 } 551 return g; 552 } 553 554 555 /** 556 * Right GenSolvablePolynomial greatest common divisor. 557 * @param P GenSolvablePolynomial. 558 * @param S GenSolvablePolynomial. 559 * @return rightGcd(P,S). 560 */ 561 @Override 562 public GenSolvablePolynomial<C> rightGcd(final GenSolvablePolynomial<C> P, 563 final GenSolvablePolynomial<C> S) { 564 if (debug) { 565 if (ComputerThreads.NO_THREADS) { 566 throw new RuntimeException("this should not happen"); 567 } 568 } 569 if (S == null || S.isZERO()) { 570 return P; 571 } 572 if (P == null || P.isZERO()) { 573 return S; 574 } 575 // parallel case 576 GenSolvablePolynomial<C> g = P.ring.getONE(); 577 //Callable<GenSolvablePolynomial<C>> c0; 578 //Callable<GenSolvablePolynomial<C>> c1; 579 List<Callable<GenSolvablePolynomial<C>>> cs = new ArrayList<Callable<GenSolvablePolynomial<C>>>(2); 580 cs.add(new Callable<GenSolvablePolynomial<C>>() { 581 582 583 public GenSolvablePolynomial<C> call() { 584 try { 585 //System.out.println("starting e1 " + e1.getClass().getName()); 586 GenSolvablePolynomial<C> g = e1.rightGcd(P, S); 587 if (debug) { 588 logger.info("SGCDParallelProxy done e1 " + e1.getClass().getName()); 589 } 590 return g; 591 } catch (PreemptingException e) { 592 throw new RuntimeException("SGCDParallelProxy e1 pre " + e); 593 //return P.ring.getONE(); 594 } catch (Exception e) { 595 //e.printStackTrace(); 596 logger.info("SGCDParallelProxy e1 " + e); 597 logger.info("SGCDParallelProxy P = " + P); 598 logger.info("SGCDParallelProxy S = " + S); 599 throw new RuntimeException("SGCDParallelProxy e1 " + e); 600 //return P.ring.getONE(); 601 } 602 } 603 }); 604 cs.add(new Callable<GenSolvablePolynomial<C>>() { 605 606 607 public GenSolvablePolynomial<C> call() { 608 try { 609 //System.out.println("starting e2 " + e2.getClass().getName()); 610 GenSolvablePolynomial<C> g = e2.rightGcd(P, S); 611 if (debug) { 612 logger.info("SGCDParallelProxy done e2 " + e2.getClass().getName()); 613 } 614 return g; 615 } catch (PreemptingException e) { 616 throw new RuntimeException("SGCDParallelProxy e2 pre " + e); 617 //return P.ring.getONE(); 618 } catch (Exception e) { 619 //e.printStackTrace(); 620 logger.info("SGCDParallelProxy e2 " + e); 621 logger.info("SGCDParallelProxy P = " + P); 622 logger.info("SGCDParallelProxy S = " + S); 623 throw new RuntimeException("SGCDParallelProxy e2 " + e); 624 //return P.ring.getONE(); 625 } 626 } 627 }); 628 try { 629 if (ComputerThreads.getTimeout() < 0) { 630 g = pool.invokeAny(cs); 631 } else { 632 g = pool.invokeAny(cs, ComputerThreads.getTimeout(), ComputerThreads.getTimeUnit()); 633 } 634 } catch (InterruptedException ignored) { 635 logger.info("InterruptedException " + ignored); 636 Thread.currentThread().interrupt(); 637 } catch (ExecutionException e) { 638 logger.info("ExecutionException " + e); 639 Thread.currentThread().interrupt(); 640 } catch (TimeoutException e) { 641 logger.info("TimeoutException after " + ComputerThreads.getTimeout() + " " 642 + ComputerThreads.getTimeUnit()); 643 g = e0.rightGcd(P, S); // fake returns 1 644 } 645 return g; 646 } 647 648}