int job_requester(int argc, char* argv[]){
	/**
	   @type simgrid process (run on all tiers)
		Every @timeout checks amount of free (non running) cores.
		If this amount is greater than some N then it sends a job request
		 to scheduler to get new batch of jobs. 

         Simgrid process parameters:
         --------------------------
         None		 
	*/
    std::string host_name = MSG_host_get_name(MSG_host_self());
    std::string CERN = "CERN";
    msg_task_t task = NULL;
    double timeout = 1000;
    long freeCoreAmount;
    int fullCoreAmount = MSG_host_get_core_number(MSG_host_self());
    MSG_process_sleep(0.01);

    while (1){
        freeCoreAmount = fullCoreAmount - xbt_str_parse_int(MSG_host_get_property_value(MSG_host_self(), "activeCore"), "error") -
                xbt_str_parse_int(MSG_host_get_property_value(MSG_host_self(), "corruptedCore"), "error");

        MSG_sem_acquire(sem_requester);
        if (GLOBAL_QUEUE->empty()){
            MSG_sem_release(sem_requester);
            break;
        }

        if (freeCoreAmount > 0){
            JobBatchRequest* jobRequest = new JobBatchRequest;
            jobRequest->coreAmount = freeCoreAmount;

            task = MSG_task_create("request", 0.0, MESSAGES_SIZE, jobRequest);

            plusLinkCounter(host_name, CERN);
            msg_error_t err = MSG_task_send(task, "scheduler");

            switch(err){
                case MSG_OK:
                    minusLinkCounter(host_name, CERN);
                    break;
                case MSG_TRANSFER_FAILURE:
                    minusLinkCounter(host_name, CERN);
                    MSG_task_destroy(task);
                    task = NULL;
                    break;
                case MSG_HOST_FAILURE:
                    MSG_task_destroy(task);
                    task = NULL;
                    break;
            }
        }else MSG_sem_release(sem_requester);

        MSG_process_sleep(timeout);
    }
    return 0;
}
void dataset_number_change(const std::string& storage_name, int change){
    /**
        Changes number of datasets on @storage_name.
        * -1 -- delete file
        * +1 -- add file

        Parameters:
        -----------
        @storage_name -- name of storage
        @change -- number of new datasets (or deleted datasets)
    */
    
    MSG_sem_acquire(sem_link);
    switch (change){
        case 1:
            ++storage_number_map[storage_name];
            break;
        case -1:
            --storage_number_map[storage_name];
            break;
        default:
            break;
    }
    MSG_sem_release(sem_link);
    return;
}
void cumulative_output_per_site(const std::string& host_name, double size){
    /**
        Add @size to cumulative output traffic of site.
        
        Parameters:
        -----------
        @host_name -- name of host which uploads file
        @size -- file size
    */
    MSG_sem_acquire(sem_link);
    cumulative_output_site[host_name] += size;
    MSG_sem_release(sem_link);
    return;
}
static int peer(int argc, char* argv[]){
  int i = 0; 
  while(i < argc) {
    double wait_time = xbt_str_parse_double(argv[i++],"Invalid wait time: %s");
    MSG_process_sleep(wait_time);
    XBT_INFO("Trying to acquire %d", i);
    MSG_sem_acquire(sem);
    XBT_INFO("Acquired %d", i);

    wait_time = xbt_str_parse_double(argv[i++], "Invalid wait time: %s");
    MSG_process_sleep(wait_time);
    XBT_INFO("Releasing %d", i);
    MSG_sem_release(sem);
    XBT_INFO("Released %d", i);
  }
  MSG_process_sleep(50);
  XBT_INFO("Done");

  return 0;
}
int addDatasetAmountT(std::string& host_name, std::string& type){
    /**
        Increases number of datasets on @host_name by one.

        Parameters:
        ----------
        @host_name -- name of host
        @type -- DISK or TAPE
    */
    MSG_sem_acquire(sem_link);
    // O -- Tape
    if (!type.compare("0")){
        TRACE_host_variable_add(host_name.c_str(), "datasetOnTape", 1);
        //TRACE_host_variable_set(host_name, "datasetOnTape", dataset_number(host_name, "0"));
    }else{
        TRACE_host_variable_add(host_name.c_str(), "datasetOnDisk", 1);
        //TRACE_host_variable_set(host_name, "datasetOnDisk", dataset_number(host_name, "1"));
    }

    MSG_sem_release(sem_link);
    return 0;
}
int writeToFile(Job* jobInfo){
	/**
		@type function
		Writes to output file information about job's metricas
		(time of pushing into queue, scheduling, starting of execution, anomalies, etc.)
		
        Parameters:
        ---------------------------
        @jobInfo job object which fields contains time metrics.
	*/
    MSG_sem_acquire(sem_link);
    static size_t n = 0;
    if (n == 0) clearFile();
    const char* typesStr[] = {"USER", "DATASTRIPPING", "MERGE", "MCStripping", "DATARECONSTRUCTION", "TURBO",  "MCRECONSTRUCTION", "WGPRODUCTION", "MCMERGE", "UNKNOWN",
                        "MCSIMULATION", "TEST", NULL};
    fprintf(FP, "%lu,%d,", jobInfo->JobId, jobInfo->successExecuted); //typesStr[jobInfo->type]
    fprintf(FP, "%.0f,%f,%f,%f,", jobInfo->SubmissionTime, jobInfo->startSchedulClock, jobInfo->StartExecTime, jobInfo->EndExecTime);
    fprintf(FP, "%s,%s\n", jobInfo->Federation.c_str(), jobInfo->JobType.c_str());
    n++;
    MSG_sem_release(sem_link);
    return(0);
}
Exemple #7
0
JNIEXPORT void JNICALL Java_org_simgrid_msg_Semaphore_release(JNIEnv * env, jobject obj) {
  msg_sem_t sem;

  sem = (msg_sem_t) (uintptr_t) env->GetLongField(obj, jsyncro_field_Semaphore_bind);
  MSG_sem_release(sem);
}