123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- #include <stdio.h>
- #include <stdint.h>
- #include <starpu.h>
- #include <stdlib.h>
- #include <time.h>
- char* names[] = {"Paul", "Jean", "Jaques", "Alain", "Brian"};
- int names_len = 5;
- int name_selected=2;
- int number_of_addition = 30;
- int stop_after_5_task = 0;
- void callback_func(void *callback_arg)
- {
- printf("Callback function got argument %p\n", callback_arg);
- }
- struct params
- {
- int i;
- float f;
- };
- void cpu_func(void *buffers[], void *cl_arg)
- {
- struct params *params = (struct params *) cl_arg;
-
- int sum = 0;
- int i = 0;
- while(i<number_of_addition*1000000)
- {
- sum+=rand();
- i++;
- }
- printf("Hello %s (params = {%i, %f} ) sum=%d\n",
- names[name_selected],
- params->i,
- params->f,
- sum);
- }
- void callback_name_changed(struct starpu_top_param* param)
- {
- char* message = (char *) malloc(256);
- sprintf(message, "Name have been changed to %s", names[name_selected]);
- starpu_top_debug_log(message);
- }
- void callback_number_addition_changed(struct starpu_top_param* param)
- {
- char* message = (char *) malloc(256);
- sprintf(message, "Number of addition is now %d", number_of_addition);
- starpu_top_debug_log(message);
- }
- struct starpu_codelet cl =
- {
-
- .where = STARPU_CPU,
- .cpu_funcs = {cpu_func, NULL},
-
- .nbuffers = 0
- };
- int main(int argc, char **argv)
- {
- int ret;
- srand ( time(NULL) );
-
- ret = starpu_init(NULL);
- STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
-
- struct starpu_top_data * loop_count =
- starpu_top_add_data_integer("Loop count", 0,124,1);
- struct starpu_top_data * remain_count =
- starpu_top_add_data_integer("Remaining loop", 0,124,1);
- struct starpu_top_data * midle_reach =
- starpu_top_add_data_boolean("Midle reached", 1);
- struct starpu_top_param* name =
- starpu_top_register_parameter_enum("Your name : ",
- &name_selected,
- names,
- names_len,
- callback_name_changed);
- struct starpu_top_param * number_of_addition_param =
- starpu_top_register_parameter_integer("Number of Millions of addition",
- &number_of_addition,
- 0,
- 50,
- callback_number_addition_changed);
- STARPU_ASSERT(number_of_addition_param != NULL);
- struct starpu_top_param * stop5_param =
- starpu_top_register_parameter_boolean("Stop after 5 task ?",
- &stop_after_5_task,
- NULL);
- STARPU_ASSERT(stop5_param != NULL);
-
- starpu_top_init_and_wait("Serveur de test HelloWorld");
-
- starpu_top_update_data_boolean(midle_reach, 0);
-
-
- struct starpu_task *task[124];
- int i;
- for(i=0; i<124; i++)
- {
- starpu_top_update_data_integer(loop_count, i);
- starpu_top_update_data_integer(remain_count, 124-i);
- if(i==62)
- {
- starpu_top_update_data_boolean(midle_reach, 1);
- }
- if(i==25)
- {
-
- name_selected = 1;
- starpu_top_update_parameter(name);
- }
- if(i>4 && stop_after_5_task)
- {
- break;
- }
- task[i]=starpu_task_create();
-
- task[i]->cl = &cl;
-
- struct params params = { i, 2.0f };
- task[i]->cl_arg = ¶ms;
- task[i]->cl_arg_size = sizeof(params);
-
- task[i]->callback_func = callback_func;
- task[i]->callback_arg = (void*) (uintptr_t) 0x42;
-
- task[i]->synchronous = 1;
-
- if(number_of_addition==42)
- starpu_top_debug_lock("debug stop point because of 42 !");
- ret = starpu_task_submit(task[i]);
- STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
- }
-
- starpu_shutdown();
- return 0;
- }
|