| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
package dr.evomodel.treedatalikelihood.continuous.cdi; |
| 27 |
|
| 28 |
import java.util.ArrayList; |
| 29 |
import java.util.HashMap; |
| 30 |
import java.util.List; |
| 31 |
import java.util.Map; |
| 32 |
import java.util.logging.Logger; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public class CDIFactory { |
| 38 |
|
| 39 |
private static Map<Integer, ResourceDetails> resourceDetailsMap = new HashMap<Integer, ResourceDetails>(); |
| 40 |
|
| 41 |
public static String getVersionInformation() { |
| 42 |
getCDIJNIWrapper(); |
| 43 |
|
| 44 |
if (CDIJNIWrapper.INSTANCE != null) { |
| 45 |
|
| 46 |
try { |
| 47 |
return CDIJNIWrapper.INSTANCE.getCitation(); |
| 48 |
} catch (UnsatisfiedLinkError ule) { |
| 49 |
return "Using CDI library v0.1 for accelerated, parallel likelihood evaluation"; |
| 50 |
|
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
return "CDI not installed/found"; |
| 55 |
} |
| 56 |
|
| 57 |
public static String getVersion() { |
| 58 |
getCDIJNIWrapper(); |
| 59 |
|
| 60 |
if (CDIJNIWrapper.INSTANCE != null) { |
| 61 |
|
| 62 |
try { |
| 63 |
return CDIJNIWrapper.INSTANCE.getVersion(); |
| 64 |
} catch (UnsatisfiedLinkError ule) { |
| 65 |
return "0.1"; |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
return "CDI not installed/found"; |
| 70 |
} |
| 71 |
|
| 72 |
public static List<ResourceDetails> getResourceDetails() { |
| 73 |
getCDIJNIWrapper(); |
| 74 |
|
| 75 |
return new ArrayList<ResourceDetails>(resourceDetailsMap.values()); |
| 76 |
} |
| 77 |
|
| 78 |
public static ResourceDetails getResourceDetails(int resourceNumber) { |
| 79 |
getCDIJNIWrapper(); |
| 80 |
return resourceDetailsMap.get(resourceNumber); |
| 81 |
} |
| 82 |
|
| 83 |
public static ContinuousDiffusionIntegrator loadCDIInstance( |
| 84 |
final PrecisionType precisionType, |
| 85 |
final int numTraits, |
| 86 |
final int dimTrait, |
| 87 |
final int bufferCount, |
| 88 |
final int diffusionCount |
| 89 |
) { |
| 90 |
boolean forceJava = Boolean.valueOf(System.getProperty("java.only")); |
| 91 |
|
| 92 |
if (!forceJava) { |
| 93 |
getCDIJNIWrapper(); |
| 94 |
if (CDIJNIWrapper.INSTANCE != null) { |
| 95 |
try { |
| 96 |
|
| 97 |
ContinuousDiffusionIntegrator cdi = null; |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
InstanceDetails details = cdi.getDetails(); |
| 104 |
|
| 105 |
if (details != null) |
| 106 |
return cdi; |
| 107 |
|
| 108 |
} catch (CDIException cdiException) { |
| 109 |
Logger.getLogger("cdi").info(" " + cdiException.getMessage()); |
| 110 |
} |
| 111 |
|
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
return new ContinuousDiffusionIntegrator.Basic( |
| 116 |
precisionType, numTraits, dimTrait, bufferCount, diffusionCount |
| 117 |
); |
| 118 |
} |
| 119 |
|
| 120 |
private static CDIJNIWrapper getCDIJNIWrapper() { |
| 121 |
if (CDIJNIWrapper.INSTANCE == null) { |
| 122 |
try { |
| 123 |
CDIJNIWrapper.loadCDILibrary(); |
| 124 |
|
| 125 |
} catch (UnsatisfiedLinkError ule) { |
| 126 |
System.err.println("Failed to load CDI library: " + ule.getMessage()); |
| 127 |
} |
| 128 |
|
| 129 |
if (CDIJNIWrapper.INSTANCE != null) { |
| 130 |
for (ResourceDetails details : CDIJNIWrapper.INSTANCE.getResourceList()) { |
| 131 |
resourceDetailsMap.put(details.getNumber(), details); |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
} |
| 136 |
|
| 137 |
return CDIJNIWrapper.INSTANCE; |
| 138 |
} |
| 139 |
} |