Search in sources :

Example 1 with SchedulerHints

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();
}
Also used : SchedulerHints(es.bsc.compss.types.annotations.SchedulerHints) MPI(es.bsc.compss.types.annotations.task.MPI) Service(es.bsc.compss.types.annotations.task.Service) Decaf(es.bsc.compss.types.annotations.task.Decaf) Services(es.bsc.compss.types.annotations.task.repeatables.Services) CtClass(javassist.CtClass) OpenCL(es.bsc.compss.types.annotations.task.OpenCL) Binary(es.bsc.compss.types.annotations.task.Binary) OmpSs(es.bsc.compss.types.annotations.task.OmpSs)

Aggregations

SchedulerHints (es.bsc.compss.types.annotations.SchedulerHints)1 Binary (es.bsc.compss.types.annotations.task.Binary)1 Decaf (es.bsc.compss.types.annotations.task.Decaf)1 MPI (es.bsc.compss.types.annotations.task.MPI)1 OmpSs (es.bsc.compss.types.annotations.task.OmpSs)1 OpenCL (es.bsc.compss.types.annotations.task.OpenCL)1 Service (es.bsc.compss.types.annotations.task.Service)1 Services (es.bsc.compss.types.annotations.task.repeatables.Services)1 CtClass (javassist.CtClass)1