Search in sources :

Example 1 with ExternalObjectParameter

use of es.bsc.compss.types.parameter.ExternalObjectParameter in project compss by bsc-wdc.

the class TaskAnalyser method processTask.

/**
 * Process the dependencies of a new task @currentTask
 *
 * @param currentTask
 */
public void processTask(Task currentTask) {
    TaskDescription params = currentTask.getTaskDescription();
    LOGGER.info("New " + (params.getType() == TaskType.METHOD ? "method" : "service") + " task(" + params.getName() + "), ID = " + currentTask.getId());
    if (drawGraph) {
        addNewTask(currentTask);
    }
    // Update task count
    Integer methodId = params.getId();
    Integer actualCount = currentTaskCount.get(methodId);
    if (actualCount == null) {
        actualCount = 0;
    }
    currentTaskCount.put(methodId, actualCount + 1);
    // Update app id task count
    Long appId = currentTask.getAppId();
    Integer taskCount = appIdToTaskCount.get(appId);
    if (taskCount == null) {
        taskCount = 0;
    }
    taskCount++;
    appIdToTaskCount.put(appId, taskCount);
    Integer totalTaskCount = appIdToTotalTaskCount.get(appId);
    if (totalTaskCount == null) {
        totalTaskCount = 0;
    }
    totalTaskCount++;
    appIdToTotalTaskCount.put(appId, totalTaskCount);
    // Check scheduling enforcing data
    int constrainingParam = -1;
    if (params.getType() == TaskType.SERVICE && params.hasTargetObject()) {
        if (params.hasReturnValue()) {
            constrainingParam = params.getParameters().length - 2;
        } else {
            constrainingParam = params.getParameters().length - 1;
        }
    }
    Parameter[] parameters = params.getParameters();
    for (int paramIdx = 0; paramIdx < parameters.length; paramIdx++) {
        Parameter p = parameters[paramIdx];
        if (DEBUG) {
            LOGGER.debug("* Parameter : " + p);
        }
        // Conversion: direction -> access mode
        AccessMode am = AccessMode.R;
        switch(p.getDirection()) {
            case IN:
                am = AccessMode.R;
                break;
            case OUT:
                am = AccessMode.W;
                break;
            case INOUT:
                am = AccessMode.RW;
                break;
        }
        // Inform the Data Manager about the new accesses
        DataAccessId daId;
        switch(p.getType()) {
            case FILE_T:
                FileParameter fp = (FileParameter) p;
                daId = DIP.registerFileAccess(am, fp.getLocation());
                break;
            case PSCO_T:
                ObjectParameter pscop = (ObjectParameter) p;
                // Check if its PSCO class and persisted to infer its type
                pscop.setType(DataType.PSCO_T);
                daId = DIP.registerObjectAccess(am, pscop.getValue(), pscop.getCode());
                break;
            case EXTERNAL_OBJECT_T:
                ExternalObjectParameter externalPSCOparam = (ExternalObjectParameter) p;
                // Check if its PSCO class and persisted to infer its type
                externalPSCOparam.setType(DataType.EXTERNAL_OBJECT_T);
                daId = DIP.registerExternalObjectAccess(am, externalPSCOparam.getId(), externalPSCOparam.getCode());
                break;
            case OBJECT_T:
                ObjectParameter op = (ObjectParameter) p;
                // Check if its PSCO class and persisted to infer its type
                if (op.getValue() instanceof StubItf && ((StubItf) op.getValue()).getID() != null) {
                    op.setType(DataType.PSCO_T);
                }
                daId = DIP.registerObjectAccess(am, op.getValue(), op.getCode());
                break;
            default:
                /*
                     * Basic types (including String). The only possible access mode is R (already checked by the API)
                     */
                continue;
        }
        // Add dependencies to the graph and register output values for future dependencies
        DependencyParameter dp = (DependencyParameter) p;
        dp.setDataAccessId(daId);
        switch(am) {
            case R:
                checkDependencyForRead(currentTask, dp);
                if (paramIdx == constrainingParam) {
                    DataAccessId.RAccessId raId = (DataAccessId.RAccessId) dp.getDataAccessId();
                    DataInstanceId dependingDataId = raId.getReadDataInstance();
                    if (dependingDataId != null) {
                        if (dependingDataId.getVersionId() > 1) {
                            currentTask.setEnforcingTask(writers.get(dependingDataId.getDataId()));
                        }
                    }
                }
                break;
            case RW:
                checkDependencyForRead(currentTask, dp);
                if (paramIdx == constrainingParam) {
                    DataAccessId.RWAccessId raId = (DataAccessId.RWAccessId) dp.getDataAccessId();
                    DataInstanceId dependingDataId = raId.getReadDataInstance();
                    if (dependingDataId != null) {
                        if (dependingDataId.getVersionId() > 1) {
                            currentTask.setEnforcingTask(writers.get(dependingDataId.getDataId()));
                        }
                    }
                }
                registerOutputValues(currentTask, dp);
                break;
            case W:
                registerOutputValues(currentTask, dp);
                break;
        }
    }
}
Also used : DependencyParameter(es.bsc.compss.types.parameter.DependencyParameter) RWAccessId(es.bsc.compss.types.data.DataAccessId.RWAccessId) DataInstanceId(es.bsc.compss.types.data.DataInstanceId) TaskDescription(es.bsc.compss.types.TaskDescription) ExternalObjectParameter(es.bsc.compss.types.parameter.ExternalObjectParameter) RWAccessId(es.bsc.compss.types.data.DataAccessId.RWAccessId) ExternalObjectParameter(es.bsc.compss.types.parameter.ExternalObjectParameter) ObjectParameter(es.bsc.compss.types.parameter.ObjectParameter) StubItf(storage.StubItf) ExternalObjectParameter(es.bsc.compss.types.parameter.ExternalObjectParameter) ObjectParameter(es.bsc.compss.types.parameter.ObjectParameter) FileParameter(es.bsc.compss.types.parameter.FileParameter) Parameter(es.bsc.compss.types.parameter.Parameter) DependencyParameter(es.bsc.compss.types.parameter.DependencyParameter) FileParameter(es.bsc.compss.types.parameter.FileParameter) DataAccessId(es.bsc.compss.types.data.DataAccessId)

Example 2 with ExternalObjectParameter

use of es.bsc.compss.types.parameter.ExternalObjectParameter in project compss by bsc-wdc.

the class COMPSsRuntimeImpl method processParameters.

/*
     * ************************************************************************************************************
     * PRIVATE HELPER METHODS
     * ********************************************************************************************************
     */
private Parameter[] processParameters(int parameterCount, Object[] parameters) {
    Parameter[] pars = new Parameter[parameterCount];
    // Parameter parsing needed, object is not serializable
    int i = 0;
    for (int npar = 0; npar < parameterCount; ++npar) {
        DataType type = (DataType) parameters[i + 1];
        Direction direction = (Direction) parameters[i + 2];
        Stream stream = (Stream) parameters[i + 3];
        String prefix = (String) parameters[i + 4];
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("  Parameter " + (npar + 1) + " has type " + type.name());
        }
        switch(type) {
            case FILE_T:
                try {
                    String fileName = (String) parameters[i];
                    String originalName = new File(fileName).getName();
                    DataLocation location = createLocation((String) parameters[i]);
                    pars[npar] = new FileParameter(direction, stream, prefix, location, originalName);
                } catch (Exception e) {
                    LOGGER.error(ERROR_FILE_NAME, e);
                    ErrorManager.fatal(ERROR_FILE_NAME, e);
                }
                break;
            case PSCO_T:
            case OBJECT_T:
                pars[npar] = new ObjectParameter(direction, stream, prefix, parameters[i], oReg.newObjectParameter(parameters[i]));
                break;
            case EXTERNAL_OBJECT_T:
                String id = (String) parameters[i];
                pars[npar] = new ExternalObjectParameter(direction, stream, prefix, id, externalObjectHashcode(id));
                break;
            default:
                /*
                     * Basic types (including String). The only possible direction is IN, warn otherwise
                     */
                if (direction != Direction.IN) {
                    LOGGER.warn(WARN_WRONG_DIRECTION + "Parameter " + npar + " is a basic type, therefore it must have IN direction");
                }
                pars[npar] = new BasicTypeParameter(type, Direction.IN, stream, prefix, parameters[i]);
                break;
        }
        i += 5;
    }
    return pars;
}
Also used : DataLocation(es.bsc.compss.types.data.location.DataLocation) Direction(es.bsc.compss.types.annotations.parameter.Direction) IOException(java.io.IOException) BasicTypeParameter(es.bsc.compss.types.parameter.BasicTypeParameter) ExternalObjectParameter(es.bsc.compss.types.parameter.ExternalObjectParameter) ExternalObjectParameter(es.bsc.compss.types.parameter.ExternalObjectParameter) ObjectParameter(es.bsc.compss.types.parameter.ObjectParameter) ExternalObjectParameter(es.bsc.compss.types.parameter.ExternalObjectParameter) ObjectParameter(es.bsc.compss.types.parameter.ObjectParameter) FileParameter(es.bsc.compss.types.parameter.FileParameter) Parameter(es.bsc.compss.types.parameter.Parameter) BasicTypeParameter(es.bsc.compss.types.parameter.BasicTypeParameter) DataType(es.bsc.compss.types.annotations.parameter.DataType) Stream(es.bsc.compss.types.annotations.parameter.Stream) InputStream(java.io.InputStream) FileParameter(es.bsc.compss.types.parameter.FileParameter) File(java.io.File)

Aggregations

ExternalObjectParameter (es.bsc.compss.types.parameter.ExternalObjectParameter)2 FileParameter (es.bsc.compss.types.parameter.FileParameter)2 ObjectParameter (es.bsc.compss.types.parameter.ObjectParameter)2 Parameter (es.bsc.compss.types.parameter.Parameter)2 TaskDescription (es.bsc.compss.types.TaskDescription)1 DataType (es.bsc.compss.types.annotations.parameter.DataType)1 Direction (es.bsc.compss.types.annotations.parameter.Direction)1 Stream (es.bsc.compss.types.annotations.parameter.Stream)1 DataAccessId (es.bsc.compss.types.data.DataAccessId)1 RWAccessId (es.bsc.compss.types.data.DataAccessId.RWAccessId)1 DataInstanceId (es.bsc.compss.types.data.DataInstanceId)1 DataLocation (es.bsc.compss.types.data.location.DataLocation)1 BasicTypeParameter (es.bsc.compss.types.parameter.BasicTypeParameter)1 DependencyParameter (es.bsc.compss.types.parameter.DependencyParameter)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 StubItf (storage.StubItf)1