disk_copy.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. You should update doxygen if you see this text.]
  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. setenv("STARPU_LIMIT_CPU_MEM", "160", 1);
  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. starpu_data_handle_t vector_handleA, vector_handleB, vector_handleC, vector_handleD, vector_handleE, vector_handleF;
  52. /* register vector in starpu */
  53. starpu_vector_data_register(&vector_handleA, STARPU_MAIN_RAM, (uintptr_t)A, NX, sizeof(double));
  54. starpu_vector_data_register(&vector_handleB, -1, (uintptr_t) NULL, NX, sizeof(double));
  55. starpu_vector_data_register(&vector_handleC, -1, (uintptr_t) NULL, NX, sizeof(double));
  56. starpu_vector_data_register(&vector_handleD, -1, (uintptr_t) NULL, NX, sizeof(double));
  57. starpu_vector_data_register(&vector_handleE, -1, (uintptr_t) NULL, NX, sizeof(double));
  58. starpu_vector_data_register(&vector_handleF, STARPU_MAIN_RAM, (uintptr_t)F, NX, sizeof(double));
  59. /* copy vector A->B, B->C... */
  60. starpu_data_cpy(vector_handleB, vector_handleA, 0, NULL, NULL);
  61. starpu_data_cpy(vector_handleC, vector_handleB, 0, NULL, NULL);
  62. starpu_data_cpy(vector_handleD, vector_handleC, 0, NULL, NULL);
  63. starpu_data_cpy(vector_handleE, vector_handleD, 0, NULL, NULL);
  64. starpu_data_cpy(vector_handleF, vector_handleE, 0, NULL, NULL);
  65. /* StarPU does not need to manipulate the array anymore so we can stop
  66. * monitoring it */
  67. /* free them */
  68. starpu_data_unregister(vector_handleA);
  69. starpu_data_unregister(vector_handleB);
  70. starpu_data_unregister(vector_handleC);
  71. starpu_data_unregister(vector_handleD);
  72. starpu_data_unregister(vector_handleE);
  73. starpu_data_unregister(vector_handleF);
  74. /* check if computation is correct */
  75. int try = 1;
  76. for (j = 0; j < NX; ++j)
  77. if (A[j] != F[j])
  78. {
  79. printf("Fail A %f != F %f \n", A[j], F[j]);
  80. try = 0;
  81. }
  82. /* free last vectors */
  83. starpu_free_flags(A, NX*sizeof(double), STARPU_MALLOC_COUNT);
  84. starpu_free_flags(F, NX*sizeof(double), STARPU_MALLOC_COUNT);
  85. /* terminate StarPU, no task can be submitted after */
  86. starpu_shutdown();
  87. if(try)
  88. FPRINTF(stderr, "TEST SUCCESS\n");
  89. else
  90. FPRINTF(stderr, "TEST FAIL\n");
  91. return (try ? EXIT_SUCCESS : EXIT_FAILURE);
  92. enodev:
  93. return 77;
  94. enoent:
  95. return 77;
  96. }
  97. //! [To be included. You should update doxygen if you see this text.]