2016-08-02 8 views
0

100 개 프로세스를 시작하는 과정이있다. 그래서 동시에 작업을 시작하고 동시에 처리를 시작하는 100 개의 프로세스가 있습니다. 활성 상태의 스텝 크기만큼 (I 예상대로)SimGrid에서 동시에 속성을 올바르게 설정하는 방법은 무엇입니까?</p> <pre><code>for (int i = 0; i < 100; ++i) { MSG_process_create("w", executor, NULL, MSG_host_self()); } </code></pre> <p>집행자 샘플 작업을 생성하고 실행 :

[ 0.000000] (2:[email protected]) Active process amount is 1 
[ 0.000000] (3:[email protected]) Active process amount is 2 
[ 0.000000] (4:[email protected]) Active process amount is 3 
.................................................... 
[ 0.000000] (101:[email protected]) Active process amount is 100 

프로세스 각각은 감소시켜야 단계 : 모든 executor 프로세스가 동시에 스타트 다 OK이므로

: 프로세스의 수를 모니터링하는 I는 void plusOneActiveProcess()void minusOneActiveProcess()executor이 완료되면 작업을 실행합니다. 그러나 그것은 발생하지 않았습니다.

[100.000000] (101:[email protected]) Active process amount is 99 
[100.000000] (2:[email protected]) Active process amount is 99 
[100.000000] (3:[email protected]) Active process amount is 99 
.................................................... 
[100.000000] (100:[email protected]) Active process amount is 99 

어떻게 올바르게 수행 할 수 있습니까?

int executor(){ 
    plusOneActiveProcess(); 
    msg_error_t a = MSG_task_execute(MSG_task_create("", 1e9, 0, NULL)); 
    minusOneActiveProcess(); 
    MSG_process_kill(MSG_process_self()); 
    return 0; 
} 

void plusOneActiveProcess(){ 
    char kot[50]; 
    long number; 
    number = xbt_str_parse_int(MSG_host_get_property_value(MSG_host_self(), "activeProcess"), "error"); 
    number++; 
    sprintf(kot, "%ld", number); 
    MSG_host_set_property_value(MSG_host_self(), "activeProcess", xbt_strdup(kot), NULL); 
    XBT_INFO("Active process amount is %s", MSG_host_get_property_value(MSG_host_self(), "activeProcess")); 
    memset(kot, 0, 50); 
} 

void minusOneActiveProcess(){ 
    char kot[50]; 
    long number; 
    number = xbt_str_parse_int(MSG_host_get_property_value(MSG_host_self(), "activeProcess"), "error"); 
    number--; 
    sprintf(kot, "%ld", number); 
    MSG_host_set_property_value(MSG_host_self(), "activeProcess", xbt_strdup(kot), NULL); 
    //XBT_INFO("Active process amount is %s", MSG_host_get_property_value(MSG_host_self(), "activeProcess")); 
    memset(kot, 0, 50); 
} 

답변

1

아하, 그 흥미로운 :

함수 plusOneActiveProcess(), minusOneActiveProcess, executor()의 코드입니다. 사실 set_property()는 SimGrid simcall이므로 set_property()에 대한 모든 호출이 항상 동일한 순서로 선형화된다는 보장이 있습니다. 하지만 get_property()는 일정한 라운드가 시작될 때 값을 반환하는 일반 함수 호출입니다. 모든 프로세스가 동일한 스케줄링 라운드에서 값을 요청하기 때문에 모두 동일한 값 (100)을 가져 와서 감소시키고 simcall을 실행하여 새 값을 밀어 넣습니다 (모든 프로세스는 99를 누르고 싶어합니다).

당신은 get + set을 원 자성으로 만들고 싶습니다. 즉, 다른 프로세스가 get_property()를하기 전에 어떤 프로세스가 업데이트 된 값을 푸시하는지 확인하십시오. 이를 위해서는 SimGrid Mutexes 등을 사용하는 것이 좋습니다.