Search in sources :

Example 11 with MethodImplementation

use of es.bsc.compss.types.implementations.MethodImplementation in project compss by bsc-wdc.

the class GATJob method prepareJob.

private JobDescription prepareJob() throws Exception {
    // Get the information related to the job
    logger.debug("Preparing GAT Job " + this.jobId);
    TaskDescription taskParams = this.taskParams;
    String targetPath = getResourceNode().getInstallDir();
    String targetHost = getResourceNode().getHost();
    String targetUser = getResourceNode().getUser();
    if (userNeeded && !targetUser.isEmpty()) {
        targetUser += "@";
    } else {
        targetUser = "";
    }
    SoftwareDescription sd = new SoftwareDescription();
    sd.setExecutable(targetPath + WORKER_SCRIPT_PATH + WORKER_SCRIPT_NAME);
    ArrayList<String> lArgs = new ArrayList<String>();
    // Common arguments: language working_dir lib_path num_obsolete [obs1... obsN] tracing [event_type task_id
    // slot_id]
    lArgs.add(LANG);
    lArgs.add(getResourceNode().getWorkingDir());
    lArgs.add(getResourceNode().getLibPath());
    LogicalData[] obsoleteFiles = getResource().pollObsoletes();
    if (obsoleteFiles != null) {
        lArgs.add("" + obsoleteFiles.length);
        for (LogicalData ld : obsoleteFiles) {
            String renaming = ld.getName();
            lArgs.add(renaming);
        }
    } else {
        lArgs.add("0");
    }
    // Check sandbox working dir
    boolean isSpecific = false;
    String sandboxDir = null;
    AbstractMethodImplementation absImpl = (AbstractMethodImplementation) this.impl;
    switch(absImpl.getMethodType()) {
        case BINARY:
            BinaryImplementation binaryImpl = (BinaryImplementation) absImpl;
            sandboxDir = binaryImpl.getWorkingDir();
            isSpecific = true;
            break;
        case MPI:
            MPIImplementation mpiImpl = (MPIImplementation) absImpl;
            sandboxDir = mpiImpl.getWorkingDir();
            isSpecific = true;
            break;
        case DECAF:
            DecafImplementation decafImpl = (DecafImplementation) absImpl;
            sandboxDir = decafImpl.getWorkingDir();
            isSpecific = true;
            break;
        case OMPSS:
            OmpSsImplementation ompssImpl = (OmpSsImplementation) absImpl;
            sandboxDir = ompssImpl.getWorkingDir();
            isSpecific = true;
            break;
        case OPENCL:
            OpenCLImplementation openclImpl = (OpenCLImplementation) absImpl;
            sandboxDir = openclImpl.getWorkingDir();
            isSpecific = true;
            break;
        case METHOD:
            sandboxDir = null;
            break;
    }
    if (sandboxDir == null || sandboxDir.isEmpty() || sandboxDir.equals(Constants.UNASSIGNED)) {
        sandboxDir = getResourceNode().getWorkingDir() + File.separator + "sandBox" + File.separator + "job_" + this.jobId;
        isSpecific = false;
    }
    // Processing parameters to get symlinks pairs to create (symlinks) and how to pass parameters in the GAT
    // Job(paramArgs)
    ArrayList<String> symlinks = new ArrayList<>();
    ArrayList<String> paramArgs = new ArrayList<>();
    processParameters(sandboxDir, symlinks, paramArgs);
    // Adding info to create symlinks between renamed files and original names
    lArgs.add(Boolean.toString(isSpecific));
    lArgs.add(sandboxDir);
    if (symlinks.size() > 0) {
        lArgs.add(String.valueOf(symlinks.size()));
        lArgs.addAll(symlinks);
    } else {
        lArgs.add("0");
    }
    lArgs.add(Boolean.toString(Tracer.isActivated()));
    lArgs.add(getHostName());
    if (debug) {
        logger.debug("hostName " + getHostName());
    }
    if (Tracer.isActivated()) {
        // event type
        lArgs.add(String.valueOf(Tracer.getTaskEventsType()));
        // task id
        lArgs.add(String.valueOf(this.taskParams.getId() + 1));
        int slot = Tracer.getNextSlot(targetHost);
        // slot id
        lArgs.add(String.valueOf(slot));
        sd.addAttribute("slot", slot);
    }
    // Language-dependent arguments: taskSandbox_dir app_dir classpath pythonpath debug storage_conf
    // method_impl_type method_impl_params
    // numSlaves [slave1,..,slaveN] numCus
    // has_target num_params par_type_1 par_1 ... par_type_n par_n
    lArgs.add(sandboxDir);
    lArgs.add(getResourceNode().getAppDir());
    lArgs.add(getClasspath());
    lArgs.add(getPythonpath());
    lArgs.add(String.valueOf(debug));
    lArgs.add(STORAGE_CONF);
    lArgs.add(String.valueOf(absImpl.getMethodType()));
    switch(absImpl.getMethodType()) {
        case METHOD:
            MethodImplementation methodImpl = (MethodImplementation) absImpl;
            lArgs.add(methodImpl.getDeclaringClass());
            String methodName = methodImpl.getAlternativeMethodName();
            if (methodName == null || methodName.isEmpty()) {
                methodName = taskParams.getName();
            }
            lArgs.add(methodName);
            break;
        case MPI:
            MPIImplementation mpiImpl = (MPIImplementation) absImpl;
            lArgs.add(mpiImpl.getMpiRunner());
            lArgs.add(mpiImpl.getBinary());
            break;
        case DECAF:
            DecafImplementation decafImpl = (DecafImplementation) absImpl;
            lArgs.add(targetPath + DecafImplementation.SCRIPT_PATH);
            String dfScript = decafImpl.getDfScript();
            if (!dfScript.startsWith(File.separator)) {
                String appPath = getResourceNode().getAppDir();
                dfScript = appPath + File.separator + dfScript;
            }
            lArgs.add(dfScript);
            String dfExecutor = decafImpl.getDfExecutor();
            if (dfExecutor == null || dfExecutor.isEmpty() || dfExecutor.equals(Constants.UNASSIGNED)) {
                dfExecutor = "executor.sh";
            }
            if (!dfExecutor.startsWith(File.separator) && !dfExecutor.startsWith("./")) {
                dfExecutor = "./" + dfExecutor;
            }
            lArgs.add(dfExecutor);
            String dfLib = decafImpl.getDfLib();
            if (dfLib == null || dfLib.isEmpty()) {
                dfLib = Constants.UNASSIGNED;
            }
            lArgs.add(dfLib);
            lArgs.add(decafImpl.getMpiRunner());
            break;
        case OMPSS:
            OmpSsImplementation ompssImpl = (OmpSsImplementation) absImpl;
            lArgs.add(ompssImpl.getBinary());
            break;
        case OPENCL:
            OpenCLImplementation openclImpl = (OpenCLImplementation) absImpl;
            lArgs.add(openclImpl.getKernel());
            break;
        case BINARY:
            BinaryImplementation binaryImpl = (BinaryImplementation) absImpl;
            lArgs.add(binaryImpl.getBinary());
            break;
    }
    // Slave nodes and cus description
    lArgs.add(String.valueOf(slaveWorkersNodeNames.size()));
    lArgs.addAll(slaveWorkersNodeNames);
    lArgs.add(String.valueOf(((MethodResourceDescription) this.impl.getRequirements()).getTotalCPUComputingUnits()));
    // Add parameter arguments already processed
    lArgs.addAll(paramArgs);
    // Conversion vector -> array
    String[] arguments = new String[lArgs.size()];
    arguments = lArgs.toArray(arguments);
    try {
        sd.setArguments(arguments);
    } catch (NullPointerException e) {
        StringBuilder sb = new StringBuilder("Null argument parameter of job " + this.jobId + " " + absImpl.getMethodDefinition() + "\n");
        int i = 0;
        for (Parameter param : taskParams.getParameters()) {
            sb.append("Parameter ").append(i).append("\n");
            DataType type = param.getType();
            sb.append("\t Type: ").append(param.getType()).append("\n");
            if (type == DataType.FILE_T || type == DataType.OBJECT_T) {
                DependencyParameter dPar = (DependencyParameter) param;
                DataAccessId dAccId = dPar.getDataAccessId();
                sb.append("\t Target: ").append(dPar.getDataTarget()).append("\n");
                if (type == DataType.OBJECT_T) {
                    if (dAccId instanceof RAccessId) {
                        sb.append("\t Direction: " + "R").append("\n");
                    } else {
                        // for the worker to know it must write the object to disk
                        sb.append("\t Direction: " + "W").append("\n");
                    }
                }
            } else if (type == DataType.STRING_T) {
                BasicTypeParameter btParS = (BasicTypeParameter) param;
                // Check spaces
                String value = btParS.getValue().toString();
                int numSubStrings = value.split(" ").length;
                sb.append("\t Num Substrings: " + Integer.toString(numSubStrings)).append("\n");
                sb.append("\t Value:" + value).append("\n");
            } else {
                // Basic types
                BasicTypeParameter btParB = (BasicTypeParameter) param;
                sb.append("\t Value: " + btParB.getValue().toString()).append("\n");
            }
            i++;
        }
        logger.error(sb.toString());
        listener.jobFailed(this, JobEndStatus.SUBMISSION_FAILED);
    }
    sd.addAttribute("jobId", jobId);
    // JEA Changed to allow execution in MN
    sd.addAttribute(SoftwareDescription.WALLTIME_MAX, absImpl.getRequirements().getWallClockLimit());
    if (absImpl.getRequirements().getHostQueues().size() > 0) {
        sd.addAttribute(SoftwareDescription.JOB_QUEUE, absImpl.getRequirements().getHostQueues().get(0));
    }
    sd.addAttribute("coreCount", absImpl.getRequirements().getTotalCPUComputingUnits());
    sd.addAttribute("gpuCount", absImpl.getRequirements().getTotalGPUComputingUnits());
    sd.addAttribute("fpgaCount", absImpl.getRequirements().getTotalFPGAComputingUnits());
    sd.addAttribute(SoftwareDescription.MEMORY_MAX, absImpl.getRequirements().getMemorySize());
    // sd.addAttribute(SoftwareDescription.SANDBOX_ROOT, "/tmp/");
    sd.addAttribute(SoftwareDescription.SANDBOX_ROOT, getResourceNode().getWorkingDir());
    sd.addAttribute(SoftwareDescription.SANDBOX_USEROOT, "true");
    sd.addAttribute(SoftwareDescription.SANDBOX_DELETE, "false");
    /*
         * sd.addAttribute(SoftwareDescription.SANDBOX_PRESTAGE_STDIN, "false");
         * sd.addAttribute(SoftwareDescription.SANDBOX_POSTSTAGE_STDOUT, "false");
         * sd.addAttribute(SoftwareDescription.SANDBOX_POSTSTAGE_STDERR, "false");
         */
    if (debug) {
        // Set standard output file for job
        File outFile = GAT.createFile(context, Protocol.ANY_URI.getSchema() + File.separator + JOBS_DIR + "job" + jobId + "_" + this.getHistory() + ".out");
        sd.setStdout(outFile);
    }
    if (debug || usingGlobus) {
        // Set standard error file for job
        File errFile = GAT.createFile(context, Protocol.ANY_URI.getSchema() + File.separator + JOBS_DIR + "job" + jobId + "_" + this.getHistory() + ".err");
        sd.setStderr(errFile);
    }
    Map<String, Object> attributes = new HashMap<String, Object>();
    attributes.put(RES_ATTR, Protocol.ANY_URI.getSchema() + targetUser + targetHost);
    attributes.put("Jobname", "compss_remote_job_" + jobId);
    ResourceDescription rd = new HardwareResourceDescription(attributes);
    if (debug) {
        logger.debug("Ready to submit job " + jobId + ":");
        logger.debug("  * Host: " + targetHost);
        logger.debug("  * Executable: " + sd.getExecutable());
        StringBuilder sb = new StringBuilder("  - Arguments:");
        for (String arg : sd.getArguments()) {
            sb.append(" ").append(arg);
        }
        logger.debug(sb.toString());
    }
    JobDescription jd = new JobDescription(sd, rd);
    // jd.setProcessCount(method.getRequirements().getProcessorCoreCount());
    return jd;
}
Also used : MethodImplementation(es.bsc.compss.types.implementations.MethodImplementation) AbstractMethodImplementation(es.bsc.compss.types.implementations.AbstractMethodImplementation) MPIImplementation(es.bsc.compss.types.implementations.MPIImplementation) RAccessId(es.bsc.compss.types.data.DataAccessId.RAccessId) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DependencyParameter(es.bsc.compss.types.parameter.DependencyParameter) BasicTypeParameter(es.bsc.compss.types.parameter.BasicTypeParameter) OpenCLImplementation(es.bsc.compss.types.implementations.OpenCLImplementation) JobDescription(org.gridlab.gat.resources.JobDescription) TaskDescription(es.bsc.compss.types.TaskDescription) DecafImplementation(es.bsc.compss.types.implementations.DecafImplementation) DataType(es.bsc.compss.types.annotations.parameter.DataType) MethodResourceDescription(es.bsc.compss.types.resources.MethodResourceDescription) BinaryImplementation(es.bsc.compss.types.implementations.BinaryImplementation) AbstractMethodImplementation(es.bsc.compss.types.implementations.AbstractMethodImplementation) HardwareResourceDescription(org.gridlab.gat.resources.HardwareResourceDescription) SoftwareDescription(org.gridlab.gat.resources.SoftwareDescription) LogicalData(es.bsc.compss.types.data.LogicalData) MethodResourceDescription(es.bsc.compss.types.resources.MethodResourceDescription) HardwareResourceDescription(org.gridlab.gat.resources.HardwareResourceDescription) ResourceDescription(org.gridlab.gat.resources.ResourceDescription) Parameter(es.bsc.compss.types.parameter.Parameter) DependencyParameter(es.bsc.compss.types.parameter.DependencyParameter) BasicTypeParameter(es.bsc.compss.types.parameter.BasicTypeParameter) File(org.gridlab.gat.io.File) OmpSsImplementation(es.bsc.compss.types.implementations.OmpSsImplementation) DataAccessId(es.bsc.compss.types.data.DataAccessId)

Example 12 with MethodImplementation

use of es.bsc.compss.types.implementations.MethodImplementation in project compss by bsc-wdc.

the class ExternalExecutor method addArguments.

private static void addArguments(ArrayList<String> lArgs, NIOTask nt, NIOWorker nw) throws JobExecutionException, SerializedObjectException {
    lArgs.add(Boolean.toString(NIOTracer.isActivated()));
    lArgs.add(Integer.toString(nt.getTaskId()));
    lArgs.add(Boolean.toString(nt.isWorkerDebug()));
    lArgs.add(STORAGE_CONF);
    // The implementation to execute externally can only be METHOD but we double check it
    if (nt.getMethodType() != MethodType.METHOD) {
        throw new JobExecutionException(ERROR_UNSUPPORTED_JOB_TYPE);
    }
    // Add method classname and methodname
    MethodImplementation impl = (MethodImplementation) nt.getMethodImplementation();
    lArgs.add(String.valueOf(impl.getMethodType()));
    lArgs.add(impl.getDeclaringClass());
    lArgs.add(impl.getAlternativeMethodName());
    // Slave nodes and cus description
    lArgs.add(String.valueOf(nt.getSlaveWorkersNodeNames().size()));
    lArgs.addAll(nt.getSlaveWorkersNodeNames());
    lArgs.add(String.valueOf(nt.getResourceDescription().getTotalCPUComputingUnits()));
    // Add target
    lArgs.add(Boolean.toString(nt.hasTarget()));
    // Add return type
    if (nt.hasReturn()) {
        DataType returnType = nt.getParams().getLast().getType();
        lArgs.add(Integer.toString(returnType.ordinal()));
    } else {
        lArgs.add("null");
    }
    // Add parameters
    lArgs.add(Integer.toString(nt.getNumParams()));
    for (NIOParam np : nt.getParams()) {
        DataType type = np.getType();
        lArgs.add(Integer.toString(type.ordinal()));
        lArgs.add(Integer.toString(np.getStream().ordinal()));
        lArgs.add(np.getPrefix());
        switch(type) {
            case FILE_T:
                // Passing originalName link instead of renamed file
                String originalFile = "";
                if (np.getData() != null) {
                    originalFile = np.getData().getName();
                }
                String destFile = new File(np.getValue().toString()).getName();
                if (!isRuntimeRenamed(destFile)) {
                    // Treat corner case: Destfile is original name. Parameter is INPUT with shared disk, so
                    // destfile should be the same as the input.
                    destFile = originalFile;
                }
                lArgs.add(originalFile + ":" + destFile + ":" + np.isPreserveSourceData() + ":" + np.isWriteFinalValue() + ":" + np.getOriginalName());
                break;
            case OBJECT_T:
            case PSCO_T:
            case EXTERNAL_OBJECT_T:
                lArgs.add(np.getValue().toString());
                lArgs.add(np.isWriteFinalValue() ? "W" : "R");
                break;
            case STRING_T:
                String value = np.getValue().toString();
                String[] vals = value.split(" ");
                int numSubStrings = vals.length;
                lArgs.add(Integer.toString(numSubStrings));
                for (String v : vals) {
                    lArgs.add(v);
                }
                break;
            default:
                lArgs.add(np.getValue().toString());
        }
    }
}
Also used : MethodImplementation(es.bsc.compss.types.implementations.MethodImplementation) JobExecutionException(es.bsc.compss.nio.exceptions.JobExecutionException) DataType(es.bsc.compss.types.annotations.parameter.DataType) File(java.io.File) NIOParam(es.bsc.compss.nio.NIOParam)

Example 13 with MethodImplementation

use of es.bsc.compss.types.implementations.MethodImplementation in project compss by bsc-wdc.

the class CERegistration method process.

@Override
public void process(TaskScheduler ts) {
    // Register the coreElement
    Integer coreId = CoreManager.registerNewCoreElement(coreElementSignature);
    if (coreId == null) {
        // CoreElement already exists, retrieve its id
        coreId = CoreManager.getCoreId(coreElementSignature);
    }
    // Retrieve the new implementation number
    int implId = CoreManager.getNumberCoreImplementations(coreId);
    // Create the implementation
    Implementation m = null;
    switch(implType) {
        case METHOD:
            if (this.implTypeArgs.length != 2) {
                ErrorManager.error("Incorrect parameters for type METHOD on " + this.coreElementSignature);
            }
            String declaringClass = EnvironmentLoader.loadFromEnvironment(implTypeArgs[0]);
            String methodName = EnvironmentLoader.loadFromEnvironment(implTypeArgs[1]);
            if (declaringClass == null || declaringClass.isEmpty()) {
                ErrorManager.error("Empty declaringClass annotation for method " + this.coreElementSignature);
            }
            if (methodName == null || methodName.isEmpty()) {
                ErrorManager.error("Empty methodName annotation for method " + this.coreElementSignature);
            }
            m = new MethodImplementation(declaringClass, methodName, coreId, implId, implConstraints);
            break;
        case MPI:
            if (this.implTypeArgs.length != 3) {
                ErrorManager.error("Incorrect parameters for type MPI on " + this.coreElementSignature);
            }
            String mpiBinary = EnvironmentLoader.loadFromEnvironment(implTypeArgs[0]);
            String mpiWorkingDir = EnvironmentLoader.loadFromEnvironment(implTypeArgs[1]);
            String mpiRunner = EnvironmentLoader.loadFromEnvironment(implTypeArgs[2]);
            if (mpiRunner == null || mpiRunner.isEmpty()) {
                ErrorManager.error("Empty mpiRunner annotation for MPI method " + this.coreElementSignature);
            }
            if (mpiBinary == null || mpiBinary.isEmpty()) {
                ErrorManager.error("Empty binary annotation for MPI method " + this.coreElementSignature);
            }
            m = new MPIImplementation(mpiBinary, mpiWorkingDir, mpiRunner, coreId, implId, this.implConstraints);
            break;
        case DECAF:
            if (this.implTypeArgs.length != 5) {
                ErrorManager.error("Incorrect parameters for type DECAF on " + this.coreElementSignature);
            }
            String dfScript = EnvironmentLoader.loadFromEnvironment(implTypeArgs[0]);
            String dfExecutor = EnvironmentLoader.loadFromEnvironment(implTypeArgs[1]);
            String dfLib = EnvironmentLoader.loadFromEnvironment(implTypeArgs[2]);
            String decafWorkingDir = EnvironmentLoader.loadFromEnvironment(implTypeArgs[3]);
            String decafRunner = EnvironmentLoader.loadFromEnvironment(implTypeArgs[4]);
            if (decafRunner == null || decafRunner.isEmpty()) {
                ErrorManager.error("Empty mpiRunner annotation for DECAF method " + this.coreElementSignature);
            }
            if (dfScript == null || dfScript.isEmpty()) {
                ErrorManager.error("Empty dfScript annotation for DECAF method " + this.coreElementSignature);
            }
            m = new DecafImplementation(dfScript, dfExecutor, dfLib, decafWorkingDir, decafRunner, coreId, implId, this.implConstraints);
            break;
        case BINARY:
            if (this.implTypeArgs.length != 2) {
                ErrorManager.error("Incorrect parameters for type BINARY on " + this.coreElementSignature);
            }
            String binary = EnvironmentLoader.loadFromEnvironment(implTypeArgs[0]);
            String binaryWorkingDir = EnvironmentLoader.loadFromEnvironment(implTypeArgs[1]);
            if (binary == null || binary.isEmpty()) {
                ErrorManager.error("Empty binary annotation for BINARY method " + this.coreElementSignature);
            }
            m = new BinaryImplementation(binary, binaryWorkingDir, coreId, implId, implConstraints);
            break;
        case OMPSS:
            if (this.implTypeArgs.length != 2) {
                ErrorManager.error("Incorrect parameters for type OMPSS on " + this.coreElementSignature);
            }
            String ompssBinary = EnvironmentLoader.loadFromEnvironment(implTypeArgs[0]);
            String ompssWorkingDir = EnvironmentLoader.loadFromEnvironment(implTypeArgs[1]);
            if (ompssBinary == null || ompssBinary.isEmpty()) {
                ErrorManager.error("Empty binary annotation for OmpSs method " + this.coreElementSignature);
            }
            m = new OmpSsImplementation(ompssBinary, ompssWorkingDir, coreId, implId, implConstraints);
            break;
        case OPENCL:
            if (this.implTypeArgs.length != 2) {
                ErrorManager.error("Incorrect parameters for type OPENCL on " + this.coreElementSignature);
            }
            String openclKernel = EnvironmentLoader.loadFromEnvironment(implTypeArgs[0]);
            String openclWorkingDir = EnvironmentLoader.loadFromEnvironment(implTypeArgs[1]);
            if (openclKernel == null || openclKernel.isEmpty()) {
                ErrorManager.error("Empty kernel annotation for OpenCL method " + this.coreElementSignature);
            }
            m = new OpenCLImplementation(openclKernel, openclWorkingDir, coreId, implId, implConstraints);
            break;
        default:
            ErrorManager.error("Unrecognised implementation type");
            break;
    }
    // Register the new implementation
    List<Implementation> newImpls = new LinkedList<>();
    newImpls.add(m);
    List<String> newSignatures = new LinkedList<>();
    newSignatures.add(implSignature);
    CoreManager.registerNewImplementations(coreId, newImpls, newSignatures);
    // Update the Resources structures
    LinkedList<Integer> newCores = new LinkedList<>();
    newCores.add(coreId);
    ResourceManager.coreElementUpdates(newCores);
    // Update the Scheduler structures
    ts.coreElementsUpdated();
    LOGGER.debug("Data structures resized and CE-resources links updated");
    sem.release();
}
Also used : MethodImplementation(es.bsc.compss.types.implementations.MethodImplementation) MPIImplementation(es.bsc.compss.types.implementations.MPIImplementation) BinaryImplementation(es.bsc.compss.types.implementations.BinaryImplementation) MPIImplementation(es.bsc.compss.types.implementations.MPIImplementation) OpenCLImplementation(es.bsc.compss.types.implementations.OpenCLImplementation) Implementation(es.bsc.compss.types.implementations.Implementation) OmpSsImplementation(es.bsc.compss.types.implementations.OmpSsImplementation) MethodImplementation(es.bsc.compss.types.implementations.MethodImplementation) DecafImplementation(es.bsc.compss.types.implementations.DecafImplementation) LinkedList(java.util.LinkedList) OpenCLImplementation(es.bsc.compss.types.implementations.OpenCLImplementation) DecafImplementation(es.bsc.compss.types.implementations.DecafImplementation) BinaryImplementation(es.bsc.compss.types.implementations.BinaryImplementation) OmpSsImplementation(es.bsc.compss.types.implementations.OmpSsImplementation)

Example 14 with MethodImplementation

use of es.bsc.compss.types.implementations.MethodImplementation in project compss by bsc-wdc.

the class IDLParser method parseCFunction.

private static void parseCFunction(String line, MethodResourceDescription currConstraints, CImplementation implementation) {
    StringBuilder implementedTaskSignatureBuffer = new StringBuilder();
    StringBuilder implementationSignatureBuffer = new StringBuilder();
    // boolean isStatic = false;
    boolean hasReturn = false;
    if (line.startsWith("static ")) {
        // isStatic = true;
        line = line.replace("static ", "");
    }
    if (!line.startsWith("void ")) {
        hasReturn = true;
    }
    line = line.replaceAll("[(|)|,|;|\n|\t]", " ");
    String[] splits = line.split("\\s+");
    CImplementation task = loadCImplementation(splits[1]);
    String methodName = task.getMethodName();
    String declaringClass = task.getClassName();
    if (implementation != null) {
        implementedTaskSignatureBuffer.append(implementation.getMethodName()).append("(");
    } else {
        implementedTaskSignatureBuffer.append(methodName).append("(");
    }
    implementationSignatureBuffer.append(methodName).append("(");
    /*
         * if (declaringClass!="NULL" && !isStatic){ implementedTaskSignatureBuffer.append("FILE_T").append(",");
         * implementationSignatureBuffer.append("FILE_T").append(","); }
         */
    if (hasReturn) {
        implementedTaskSignatureBuffer.append("FILE_T").append(",");
        implementationSignatureBuffer.append("FILE_T").append(",");
    }
    // Computes the method's signature
    for (int i = 2; i < splits.length; i++) {
        String paramDirection = splits[i++];
        String paramType = splits[i++];
        String type = "FILE_T";
        /*
             * OLD version C-binding String type = "OBJECT_T";
             */
        if (paramDirection.toUpperCase().compareTo("INOUT") == 0) {
            type = "FILE_T";
        } else if (paramDirection.toUpperCase().compareTo("OUT") == 0) {
            type = "FILE_T";
        } else if (paramType.toUpperCase().compareTo("FILE") == 0) {
            type = "FILE_T";
        } else if (paramType.compareTo("boolean") == 0) {
            type = "BOOLEAN_T";
        } else if (paramType.compareTo("char") == 0) {
            type = "CHAR_T";
        } else if (paramType.compareTo("int") == 0) {
            type = "INT_T";
        } else if (paramType.compareTo("float") == 0) {
            type = "FLOAT_T";
        } else if (paramType.compareTo("double") == 0) {
            type = "DOUBLE_T";
        } else if (paramType.compareTo("byte") == 0) {
            type = "BYTE_T";
        } else if (paramType.compareTo("short") == 0) {
            type = "SHORT_T";
        } else if (paramType.compareTo("long") == 0) {
            type = "LONG_T";
        } else if (paramType.compareTo("string") == 0) {
            type = "STRING_T";
        }
        implementedTaskSignatureBuffer.append(type).append(",");
        implementationSignatureBuffer.append(type).append(",");
    // String paramName = splits[i];
    }
    implementedTaskSignatureBuffer.deleteCharAt(implementedTaskSignatureBuffer.lastIndexOf(","));
    implementationSignatureBuffer.deleteCharAt(implementationSignatureBuffer.lastIndexOf(","));
    implementedTaskSignatureBuffer.append(")");
    implementationSignatureBuffer.append(")");
    if (implementation != null) {
        implementedTaskSignatureBuffer.append(implementation.getClassName());
    } else {
        implementedTaskSignatureBuffer.append(declaringClass);
    }
    implementationSignatureBuffer.append(declaringClass);
    String taskSignature = implementedTaskSignatureBuffer.toString();
    String implementationSignature = implementationSignatureBuffer.toString();
    // Create the core Element if it does not exist
    Integer coreId = CoreManager.registerNewCoreElement(taskSignature);
    if (coreId == null) {
        // The coreId already exists
        coreId = CoreManager.getCoreId(taskSignature);
    }
    LOGGER.debug("CoreId for task " + taskSignature + " is " + coreId);
    // Add the implementation to the core element
    int implId = CoreManager.getNumberCoreImplementations(coreId);
    List<Implementation> newImpls = new LinkedList<>();
    MethodImplementation m = new MethodImplementation(declaringClass, methodName, coreId, implId, currConstraints);
    newImpls.add(m);
    List<String> newSigns = new LinkedList<>();
    newSigns.add(implementationSignature);
    CoreManager.registerNewImplementations(coreId, newImpls, newSigns);
    LOGGER.debug("[IDL Parser] Adding implementation: " + declaringClass + "." + methodName + " for CE id " + coreId);
}
Also used : MethodImplementation(es.bsc.compss.types.implementations.MethodImplementation) MethodImplementation(es.bsc.compss.types.implementations.MethodImplementation) Implementation(es.bsc.compss.types.implementations.Implementation) LinkedList(java.util.LinkedList)

Example 15 with MethodImplementation

use of es.bsc.compss.types.implementations.MethodImplementation in project compss by bsc-wdc.

the class TestCompatible method checkResourcesAssignedToImpl.

private static String checkResourcesAssignedToImpl(Implementation impl, Worker<?> resource) {
    if ((impl.getTaskType().equals(TaskType.METHOD) && resource.getType().equals(Resource.Type.SERVICE)) || (impl.getTaskType().equals(TaskType.SERVICE) && resource.getType().equals(Resource.Type.WORKER))) {
        return "types";
    }
    if (resource.getType() == Worker.Type.WORKER) {
        MethodImplementation mImpl = (MethodImplementation) impl;
        MethodResourceDescription iDescription = mImpl.getRequirements();
        MethodWorker worker = (MethodWorker) resource;
        MethodResourceDescription wDescription = (MethodResourceDescription) worker.getDescription();
        /*
             * *********************************************************************************************************
             * COMPUTING UNITS
             **********************************************************************************************************/
        if ((iDescription.getTotalCPUComputingUnits() >= MethodResourceDescription.ONE_INT) && (wDescription.getTotalCPUComputingUnits() >= MethodResourceDescription.ONE_INT) && (wDescription.getTotalCPUComputingUnits() < iDescription.getTotalCPUComputingUnits())) {
            return "computingUnits";
        }
        /*
             * *********************************************************************************************************
             * PROCESSOR
             ***********************************************************************************************************/
        for (Processor ip : iDescription.getProcessors()) {
            // Check if processor can be executed in worker
            boolean canBeHosted = false;
            for (Processor wp : wDescription.getProcessors()) {
                // Static checks
                if (!ip.getName().equals(MethodResourceDescription.UNASSIGNED_STR) && !wp.getName().equals(MethodResourceDescription.UNASSIGNED_STR) && !wp.getName().equals(ip.getName())) {
                    // System.out.println("DUE TO: " + ip.getName() + " != " + wp.getName());
                    continue;
                }
                if (ip.getSpeed() != MethodResourceDescription.UNASSIGNED_FLOAT && wp.getSpeed() != MethodResourceDescription.UNASSIGNED_FLOAT && wp.getSpeed() < ip.getSpeed()) {
                    // System.out.println("DUE TO: " + ip.getSpeed() + " != " + wp.getSpeed());
                    continue;
                }
                if (!ip.getArchitecture().equals(MethodResourceDescription.UNASSIGNED_STR) && !wp.getArchitecture().equals(MethodResourceDescription.UNASSIGNED_STR) && !wp.getArchitecture().equals(ip.getArchitecture())) {
                    // System.out.println("DUE TO: " + ip.getArchitecture() + " != " + wp.getArchitecture());
                    continue;
                }
                if ((!ip.getPropName().equals(MethodResourceDescription.UNASSIGNED_STR)) && (!wp.getPropName().equals(MethodResourceDescription.UNASSIGNED_STR)) && (!ip.getPropName().equals(wp.getPropName()))) {
                    // System.out.println("DUE TO: " + ip.getPropName() + " != " + wp.getPropName());
                    continue;
                }
                if ((!ip.getPropValue().equals(MethodResourceDescription.UNASSIGNED_STR)) && (!wp.getPropValue().equals(MethodResourceDescription.UNASSIGNED_STR)) && (!ip.getPropValue().equals(wp.getPropValue()))) {
                    // System.out.println("DUE TO: " + ip.getPropValue() + " != " + wp.getPropValue());
                    continue;
                }
                // Dynamic checks
                if (wp.getComputingUnits() >= ip.getComputingUnits()) {
                    canBeHosted = true;
                    break;
                } else {
                // System.out.println("DUE TO: " + ip.getComputingUnits() + " != " + wp.getComputingUnits());
                }
            }
            if (!canBeHosted) {
                return "processor";
            }
        }
        /*
             * *********************************************************************************************************
             * MEMORY
             ***********************************************************************************************************/
        if ((iDescription.getMemorySize() != MethodResourceDescription.UNASSIGNED_FLOAT) && (wDescription.getMemorySize() != MethodResourceDescription.UNASSIGNED_FLOAT) && (wDescription.getMemorySize() < iDescription.getMemorySize())) {
            return "memorySize";
        }
        if ((!iDescription.getMemoryType().equals(MethodResourceDescription.UNASSIGNED_STR)) && (!iDescription.getMemoryType().equals(MethodResourceDescription.UNASSIGNED_STR)) && (!wDescription.getMemoryType().equals(iDescription.getMemoryType()))) {
            return "memoryType";
        }
        /*
             * *********************************************************************************************************
             * STORAGE
             ***********************************************************************************************************/
        if ((iDescription.getStorageSize() != MethodResourceDescription.UNASSIGNED_FLOAT) && (wDescription.getStorageSize() != MethodResourceDescription.UNASSIGNED_FLOAT) && (wDescription.getStorageSize() < iDescription.getStorageSize())) {
            return "storageSize";
        }
        if ((!iDescription.getStorageType().equals(MethodResourceDescription.UNASSIGNED_STR)) && (!iDescription.getStorageType().equals(MethodResourceDescription.UNASSIGNED_STR)) && (!wDescription.getStorageType().equals(iDescription.getStorageType()))) {
            return "storageType";
        }
        /*
             * *********************************************************************************************************
             * OPERATING SYSTEM
             ***********************************************************************************************************/
        if ((!iDescription.getOperatingSystemType().equals(MethodResourceDescription.UNASSIGNED_STR)) && (!iDescription.getOperatingSystemType().equals(MethodResourceDescription.UNASSIGNED_STR)) && (!wDescription.getOperatingSystemType().equals(iDescription.getOperatingSystemType()))) {
            return "operatingSystemType";
        }
        if ((!iDescription.getOperatingSystemDistribution().equals(MethodResourceDescription.UNASSIGNED_STR)) && (!iDescription.getOperatingSystemDistribution().equals(MethodResourceDescription.UNASSIGNED_STR)) && (!wDescription.getOperatingSystemDistribution().equals(iDescription.getOperatingSystemDistribution()))) {
            return "operatingSystemDistribution";
        }
        if ((!iDescription.getOperatingSystemVersion().equals(MethodResourceDescription.UNASSIGNED_STR)) && (!iDescription.getOperatingSystemVersion().equals(MethodResourceDescription.UNASSIGNED_STR)) && (!wDescription.getOperatingSystemVersion().equals(iDescription.getOperatingSystemVersion()))) {
            return "operatingSystemVersion";
        }
        /*
             * *********************************************************************************************************
             * APPLICATION SOFTWARE
             ***********************************************************************************************************/
        if (!(iDescription.getAppSoftware().isEmpty()) && !(wDescription.getAppSoftware().containsAll(iDescription.getAppSoftware()))) {
            return "appSoftware";
        }
        /*
             * *********************************************************************************************************
             * HOST QUEUE
             ***********************************************************************************************************/
        if (!(iDescription.getHostQueues().isEmpty()) && !(wDescription.getHostQueues().containsAll(iDescription.getHostQueues()))) {
            return "hostQueues";
        }
    } else if (resource.getType() == Worker.Type.SERVICE) {
        ServiceImplementation sImpl = (ServiceImplementation) impl;
        ServiceResourceDescription iDescription = sImpl.getRequirements();
        ServiceWorker worker = (ServiceWorker) resource;
        ServiceResourceDescription wDescription = (ServiceResourceDescription) worker.getDescription();
        if (!wDescription.getServiceName().equals(iDescription.getServiceName())) {
            return "ServiceName";
        }
        if (!wDescription.getNamespace().equals(iDescription.getNamespace())) {
            return "Namespace";
        }
        if (!wDescription.getPort().equals(iDescription.getPort())) {
            return "Port";
        }
    } else {
        return "Unknown resource type";
    }
    /*
         * ************************************************************************************************************
         * ALL CONSTAINT VALUES OK
         *************************************************************************************************************/
    return null;
}
Also used : MethodImplementation(es.bsc.compss.types.implementations.MethodImplementation) ServiceResourceDescription(es.bsc.compss.types.resources.ServiceResourceDescription) Processor(es.bsc.compss.types.resources.components.Processor) ServiceImplementation(es.bsc.compss.types.implementations.ServiceImplementation) ServiceWorker(es.bsc.compss.types.resources.ServiceWorker) MethodWorker(es.bsc.compss.types.resources.MethodWorker) MethodResourceDescription(es.bsc.compss.types.resources.MethodResourceDescription)

Aggregations

MethodImplementation (es.bsc.compss.types.implementations.MethodImplementation)16 Implementation (es.bsc.compss.types.implementations.Implementation)11 MethodResourceDescription (es.bsc.compss.types.resources.MethodResourceDescription)8 Processor (es.bsc.compss.types.resources.components.Processor)4 LinkedList (java.util.LinkedList)4 AbstractMethodImplementation (es.bsc.compss.types.implementations.AbstractMethodImplementation)3 BinaryImplementation (es.bsc.compss.types.implementations.BinaryImplementation)3 DecafImplementation (es.bsc.compss.types.implementations.DecafImplementation)3 MPIImplementation (es.bsc.compss.types.implementations.MPIImplementation)3 OmpSsImplementation (es.bsc.compss.types.implementations.OmpSsImplementation)3 OpenCLImplementation (es.bsc.compss.types.implementations.OpenCLImplementation)3 CloudMethodResourceDescription (es.bsc.compss.types.resources.description.CloudMethodResourceDescription)3 NIOParam (es.bsc.compss.nio.NIOParam)2 DataType (es.bsc.compss.types.annotations.parameter.DataType)2 ServiceImplementation (es.bsc.compss.types.implementations.ServiceImplementation)2 PriorityQueue (java.util.PriorityQueue)2 BeforeClass (org.junit.BeforeClass)2 Test (org.junit.Test)2 NIOTask (es.bsc.compss.nio.NIOTask)1 JobExecutionException (es.bsc.compss.nio.exceptions.JobExecutionException)1