mlr.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010, 2015 Université de Bordeaux
  4. * Copyright (C) 2010, 2011, 2012, 2013 CNRS
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. /*
  18. * This examples demonstrates how to construct and submit a task to StarPU and
  19. * more precisely:
  20. * - how to...
  21. */
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <stdint.h>
  25. #include <starpu.h>
  26. int sum;
  27. void cl_perf_func(struct starpu_task *task, double *parameters)
  28. {
  29. starpu_codelet_unpack_args(task->cl_arg,
  30. &parameters[0],
  31. &parameters[1],
  32. &parameters[2]);
  33. }
  34. void cpu_func(void *buffers[], void *cl_arg)
  35. {
  36. double m,n,k;
  37. starpu_codelet_unpack_args(cl_arg,
  38. &m,
  39. &n,
  40. &k);
  41. for(int i=0; i < (int) (m*m*n); i++)
  42. sum+=i;
  43. for(int i=0; i < (int) (n*n*n*k); i++)
  44. sum+=i;
  45. }
  46. int main(int argc, char **argv)
  47. {
  48. struct starpu_codelet cl;
  49. starpu_init(NULL);
  50. memset(&cl, 0, sizeof(cl));
  51. cl.cpu_funcs[0] = cpu_func;
  52. cl.cpu_funcs_name[0] = "mlr_codelet";
  53. cl.nbuffers = 0;
  54. cl.name="test_mlr";
  55. /* ############################################ */
  56. /* Defining perfmodel, #parameters and their names */
  57. struct starpu_perfmodel *model = calloc(1,sizeof(struct starpu_perfmodel));
  58. cl.model = model;
  59. cl.model->type = STARPU_MULTIPLE_REGRESSION_BASED;
  60. cl.model->symbol = cl.name;
  61. cl.model->parameters = cl_perf_func;
  62. cl.model->nparameters = 3;
  63. cl.model->parameters_names = (const char **) calloc(1, cl.model->nparameters*sizeof(char *));
  64. cl.model->parameters_names[0] = "M";
  65. cl.model->parameters_names[1] = "N";
  66. cl.model->parameters_names[2] = "K";
  67. cl.model->ncombinations = 2;
  68. cl.model->combinations = (unsigned **) malloc(cl.model->ncombinations*sizeof(unsigned *));
  69. if (cl.model->combinations)
  70. {
  71. for (unsigned i = 0; i < cl.model->ncombinations; i++)
  72. {
  73. cl.model->combinations[i] = (unsigned *) malloc(cl.model->nparameters*sizeof(unsigned));
  74. }
  75. }
  76. cl.model->combinations[0][0] = 2;
  77. cl.model->combinations[0][1] = 1;
  78. cl.model->combinations[0][2] = 0;
  79. cl.model->combinations[1][0] = 0;
  80. cl.model->combinations[1][1] = 3;
  81. cl.model->combinations[1][2] = 1;
  82. /* ############################################ */
  83. sum=0;
  84. double *parameters = (double*) calloc(1,cl.model->nparameters*sizeof(double));
  85. for(int i=0; i < 42; i++)
  86. {
  87. parameters[0] = (double) ((rand() % 10)+1);
  88. parameters[1] = (double) ((rand() % 10)+1);
  89. parameters[2] = (double) ((rand() % 10)+1);
  90. for(int j=0; j < 42; j++)
  91. starpu_insert_task(&cl,
  92. STARPU_VALUE, &parameters[0], sizeof(double),
  93. STARPU_VALUE, &parameters[1], sizeof(double),
  94. STARPU_VALUE, &parameters[2], sizeof(double),
  95. 0);
  96. }
  97. starpu_shutdown();
  98. return 0;
  99. }