Debian Codegraph @

src/dr/evomodel/treedatalikelihood/continuous/cdi/CDIFactory.java

raw symbols SCIP
1 /*
2 * CDIFactory.java
3 *
4 * Copyright (c) 2002-2016 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
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 * @author Marc A. Suchard
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 // Do nothing yet
97 ContinuousDiffusionIntegrator cdi = null;
98
99 // Beagle beagle = new BeagleJNIImpl(
100 // tipCount,
101 // );
102
103 InstanceDetails details = cdi.getDetails();
104
105 if (details != null) // If resourceList/requirements not met, details == null here
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 }