use of es.bsc.compss.types.annotations.SchedulerHints in project compss by bsc-wdc.
the class ITAppEditor method replaceTaskMethodCall.
/**
* Replaces calls to local methods by executeTask
*
* @param methodName
* @param className
* @param declaredMethod
* @param calledMethod
* @return
*/
private String replaceTaskMethodCall(String methodName, String className, Method declaredMethod, CtMethod calledMethod) throws CannotCompileException {
if (DEBUG) {
LOGGER.debug("Found call to remote method " + methodName);
}
Class<?> retType = declaredMethod.getReturnType();
boolean isVoid = retType.equals(void.class);
boolean isStatic = Modifier.isStatic(calledMethod.getModifiers());
Class<?>[] paramTypes = declaredMethod.getParameterTypes();
int numParams = paramTypes.length;
if (!isStatic) {
numParams++;
}
if (!isVoid) {
numParams++;
}
// Build the executeTask call string
StringBuilder executeTask = new StringBuilder();
executeTask.append(itApiVar).append(EXECUTE_TASK);
executeTask.append(itAppIdVar).append(',');
// Common values
boolean isPrioritary = Boolean.parseBoolean(Constants.IS_NOT_PRIORITARY_TASK);
int numNodes = Constants.SINGLE_NODE;
// Scheduler hints values
boolean isReplicated = Boolean.parseBoolean(Constants.IS_NOT_REPLICATED_TASK);
boolean isDistributed = Boolean.parseBoolean(Constants.IS_NOT_DISTRIBUTED_TASK);
if (declaredMethod.isAnnotationPresent(SchedulerHints.class)) {
SchedulerHints schedAnnot = declaredMethod.getAnnotation(SchedulerHints.class);
isReplicated = Boolean.parseBoolean(EnvironmentLoader.loadFromEnvironment(schedAnnot.isReplicated()));
isDistributed = Boolean.parseBoolean(EnvironmentLoader.loadFromEnvironment(schedAnnot.isDistributed()));
}
// Specific implementation values
boolean isMethod = !(declaredMethod.isAnnotationPresent(Service.class) || declaredMethod.isAnnotationPresent(Services.class));
if (isMethod) {
// Method: native, MPI, OMPSs, Binary, OpenCL, etc.
if (declaredMethod.isAnnotationPresent(es.bsc.compss.types.annotations.task.Method.class)) {
es.bsc.compss.types.annotations.task.Method methodAnnot = declaredMethod.getAnnotation(es.bsc.compss.types.annotations.task.Method.class);
isPrioritary = Boolean.parseBoolean(EnvironmentLoader.loadFromEnvironment(methodAnnot.priority()));
} else if (declaredMethod.isAnnotationPresent(MPI.class)) {
MPI mpiAnnot = declaredMethod.getAnnotation(MPI.class);
isPrioritary = Boolean.parseBoolean(EnvironmentLoader.loadFromEnvironment(mpiAnnot.priority()));
// Parse computingNodes from environment if needed
String numNodesSTR = EnvironmentLoader.loadFromEnvironment(mpiAnnot.computingNodes());
numNodes = (numNodesSTR != null && !numNodesSTR.isEmpty() && !numNodesSTR.equals(Constants.UNASSIGNED)) ? Integer.valueOf(numNodesSTR) : Constants.SINGLE_NODE;
} else if (declaredMethod.isAnnotationPresent(Decaf.class)) {
Decaf decafAnnot = declaredMethod.getAnnotation(Decaf.class);
isPrioritary = Boolean.parseBoolean(EnvironmentLoader.loadFromEnvironment(decafAnnot.priority()));
// Parse computingNodes from environment if needed
String numNodesSTR = EnvironmentLoader.loadFromEnvironment(decafAnnot.computingNodes());
numNodes = (numNodesSTR != null && !numNodesSTR.isEmpty() && !numNodesSTR.equals(Constants.UNASSIGNED)) ? Integer.valueOf(numNodesSTR) : Constants.SINGLE_NODE;
} else if (declaredMethod.isAnnotationPresent(OmpSs.class)) {
OmpSs ompssAnnot = declaredMethod.getAnnotation(OmpSs.class);
isPrioritary = Boolean.parseBoolean(EnvironmentLoader.loadFromEnvironment(ompssAnnot.priority()));
} else if (declaredMethod.isAnnotationPresent(OpenCL.class)) {
OpenCL openCLAnnot = declaredMethod.getAnnotation(OpenCL.class);
isPrioritary = Boolean.parseBoolean(EnvironmentLoader.loadFromEnvironment(openCLAnnot.priority()));
} else if (declaredMethod.isAnnotationPresent(Binary.class)) {
Binary binaryAnnot = declaredMethod.getAnnotation(Binary.class);
isPrioritary = Boolean.parseBoolean(EnvironmentLoader.loadFromEnvironment(binaryAnnot.priority()));
}
executeTask.append("\"").append(className).append("\"").append(',');
executeTask.append("\"").append(methodName).append("\"").append(',');
} else {
// Service
Service serviceAnnot = declaredMethod.getAnnotation(Service.class);
executeTask.append("\"").append(serviceAnnot.namespace()).append("\"").append(',');
executeTask.append("\"").append(serviceAnnot.name()).append("\"").append(',');
executeTask.append("\"").append(serviceAnnot.port()).append("\"").append(',');
executeTask.append("\"").append(methodName).append("\"").append(',');
}
// Add scheduler common values
executeTask.append(isPrioritary).append(',');
executeTask.append(numNodes).append(",");
executeTask.append(isReplicated).append(',');
executeTask.append(isDistributed).append(',');
// Add if call has target object or not
executeTask.append(!isStatic).append(',');
// Add parameters
executeTask.append(numParams);
if (numParams == 0) {
executeTask.append(",null);");
} else {
Annotation[][] paramAnnot = declaredMethod.getParameterAnnotations();
CallInformation callInformation = processParameters(declaredMethod, paramAnnot, paramTypes, isVoid, isStatic, isMethod, numParams, retType);
executeTask.append(callInformation.getToAppend());
executeTask.insert(0, callInformation.getToPrepend());
}
return executeTask.toString();
}
Aggregations