disk_copy.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2013 Corentin Salingue
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. //! [To be included]
  17. /* Try to write into disk memory
  18. * Use mechanism to push datas from main ram to disk ram
  19. */
  20. #include <starpu.h>
  21. #include <stdlib.h>
  22. #include <stdio.h>
  23. #include <math.h>
  24. /* size of one vector */
  25. #define NX (30*1000000/sizeof(double))
  26. #define FPRINTF(ofile, fmt, ...) do { if (!getenv("STARPU_SSILENT")) {fprintf(ofile, fmt, ## __VA_ARGS__); }} while(0)
  27. int main(int argc, char **argv)
  28. {
  29. double * A,*B,*C,*D,*E,*F;
  30. /* limit main ram to force to push in disk */
  31. putenv("STARPU_LIMIT_CPU_MEM=160");
  32. /* Initialize StarPU with default configuration */
  33. int ret = starpu_init(NULL);
  34. if (ret == -ENODEV) goto enodev;
  35. /* register a disk */
  36. int new_dd = starpu_disk_register(&starpu_disk_stdio_ops, (void *) "/tmp/", 1024*1024*200);
  37. /* can't write on /tmp/ */
  38. if (new_dd == -ENOENT) goto enoent;
  39. unsigned dd = (unsigned) new_dd;
  40. /* allocate two memory spaces */
  41. starpu_malloc_flags((void **)&A, NX*sizeof(double), STARPU_MALLOC_COUNT);
  42. starpu_malloc_flags((void **)&F, NX*sizeof(double), STARPU_MALLOC_COUNT);
  43. FPRINTF(stderr, "TEST DISK MEMORY \n");
  44. unsigned int j;
  45. /* initialization with bad values */
  46. for(j = 0; j < NX; ++j)
  47. {
  48. A[j] = j;
  49. F[j] = -j;
  50. }
  51. /* Tell StaPU to associate the "vector" vector with the "vector_handle"
  52. * identifier. When a task needs to access a piece of data, it should
  53. * refer to the handle that is associated to it.
  54. * In the case of the "vector" data interface:
  55. * - the first argument of the registration method is a pointer to the
  56. * handle that should describe the data
  57. * - the second argument is the memory node where the data (ie. "vector")
  58. * resides initially: 0 stands for an address in main memory, as
  59. * opposed to an adress on a GPU for instance.
  60. * - the third argument is the adress of the vector in RAM
  61. * - the fourth argument is the number of elements in the vector
  62. * - the fifth argument is the size of each element.
  63. */
  64. starpu_data_handle_t vector_handleA, vector_handleB, vector_handleC, vector_handleD, vector_handleE, vector_handleF;
  65. /* register vector in starpu */
  66. starpu_vector_data_register(&vector_handleA, 0, (uintptr_t)A, NX, sizeof(double));
  67. starpu_vector_data_register(&vector_handleB, -1, (uintptr_t) NULL, NX, sizeof(double));
  68. starpu_vector_data_register(&vector_handleC, -1, (uintptr_t) NULL, NX, sizeof(double));
  69. starpu_vector_data_register(&vector_handleD, -1, (uintptr_t) NULL, NX, sizeof(double));
  70. starpu_vector_data_register(&vector_handleE, -1, (uintptr_t) NULL, NX, sizeof(double));
  71. starpu_vector_data_register(&vector_handleF, 0, (uintptr_t)F, NX, sizeof(double));
  72. /* copy vector A->B, B->C... */
  73. starpu_data_cpy(vector_handleB, vector_handleA, 0, NULL, NULL);
  74. starpu_data_cpy(vector_handleC, vector_handleB, 0, NULL, NULL);
  75. starpu_data_cpy(vector_handleD, vector_handleC, 0, NULL, NULL);
  76. starpu_data_cpy(vector_handleE, vector_handleD, 0, NULL, NULL);
  77. starpu_data_cpy(vector_handleF, vector_handleE, 0, NULL, NULL);
  78. /* StarPU does not need to manipulate the array anymore so we can stop
  79. * monitoring it */
  80. /* free them */
  81. starpu_data_unregister(vector_handleA);
  82. starpu_data_unregister(vector_handleB);
  83. starpu_data_unregister(vector_handleC);
  84. starpu_data_unregister(vector_handleD);
  85. starpu_data_unregister(vector_handleE);
  86. starpu_data_unregister(vector_handleF);
  87. /* check if computation is correct */
  88. int try = 1;
  89. for (j = 0; j < NX; ++j)
  90. if (A[j] != F[j])
  91. {
  92. printf("Fail A %f != F %f \n", A[j], F[j]);
  93. try = 0;
  94. }
  95. /* free last vectors */
  96. starpu_free_flags(A, NX*sizeof(double), STARPU_MALLOC_COUNT);
  97. starpu_free_flags(F, NX*sizeof(double), STARPU_MALLOC_COUNT);
  98. /* terminate StarPU, no task can be submitted after */
  99. starpu_shutdown();
  100. if(try)
  101. FPRINTF(stderr, "TEST SUCCESS\n");
  102. else
  103. FPRINTF(stderr, "TEST FAIL\n");
  104. return (try ? EXIT_SUCCESS : EXIT_FAILURE);
  105. enodev:
  106. return 77;
  107. enoent:
  108. return 77;
  109. }
  110. //! [To be included]