有其發射100個處理的方法:如何在SimGrid中同時正確設置屬性?
for (int i = 0; i < 100; ++i) {
MSG_process_create("w", executor, NULL, MSG_host_self());
}
的執行程序創建樣品任務並執行它。所以有100個進程同時開始執行任務並完成同時完成任務。對於監控的進程數我有void plusOneActiveProcess()
和void minusOneActiveProcess()
:
因爲所有executor
進程同時開始一切正常:
[ 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
完成執行任務時的進程。但它沒有發生:
[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
如何正確地做到這一點?
這是功能plusOneActiveProcess()
,minusOneActiveProcess
,executor()
代碼:
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);
}