disk_copy.c 3.8 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. /* Try to write into disk memory
  17. * Use mechanism to push datas from main ram to disk ram
  18. */
  19. #include <starpu.h>
  20. #include <stdlib.h>
  21. #include <stdio.h>
  22. #include <math.h>
  23. #include <common/config.h>
  24. #include "../helper.h"
  25. /* size of one vector */
  26. #if SIZEOF_VOID_P == 4
  27. #define NX (30*1000/sizeof(double))
  28. #else
  29. #define NX (30*1000000/sizeof(double))
  30. #endif
  31. int main(int argc, char **argv)
  32. {
  33. double * A,*B,*C,*D,*E,*F;
  34. /* limit main ram to force to push in disk */
  35. putenv("STARPU_LIMIT_CPU_MEM=160");
  36. /* Initialize StarPU with default configuration */
  37. int ret = starpu_init(NULL);
  38. if (ret == -ENODEV) goto enodev;
  39. /* register a disk */
  40. int new_dd = starpu_disk_register(&starpu_disk_stdio_ops, (void *) "/tmp", 1024*1024*200);
  41. /* can't write on /tmp/ */
  42. if (new_dd == -ENOENT) goto enoent;
  43. unsigned dd = (unsigned) new_dd;
  44. /* allocate two memory spaces */
  45. starpu_malloc_flags((void **)&A, NX*sizeof(double), STARPU_MALLOC_COUNT);
  46. starpu_malloc_flags((void **)&F, NX*sizeof(double), STARPU_MALLOC_COUNT);
  47. FPRINTF(stderr, "TEST DISK MEMORY \n");
  48. unsigned int j;
  49. /* initialization with bad values */
  50. for(j = 0; j < NX; ++j)
  51. {
  52. A[j] = j;
  53. F[j] = -j;
  54. }
  55. starpu_data_handle_t vector_handleA, vector_handleB, vector_handleC, vector_handleD, vector_handleE, vector_handleF;
  56. /* register vector in starpu */
  57. starpu_vector_data_register(&vector_handleA, STARPU_MAIN_RAM, (uintptr_t)A, NX, sizeof(double));
  58. starpu_vector_data_register(&vector_handleB, -1, (uintptr_t) NULL, NX, sizeof(double));
  59. starpu_vector_data_register(&vector_handleC, -1, (uintptr_t) NULL, NX, sizeof(double));
  60. starpu_vector_data_register(&vector_handleD, -1, (uintptr_t) NULL, NX, sizeof(double));
  61. starpu_vector_data_register(&vector_handleE, -1, (uintptr_t) NULL, NX, sizeof(double));
  62. starpu_vector_data_register(&vector_handleF, STARPU_MAIN_RAM, (uintptr_t)F, NX, sizeof(double));
  63. /* copy vector A->B, B->C... */
  64. starpu_data_cpy(vector_handleB, vector_handleA, 0, NULL, NULL);
  65. starpu_data_cpy(vector_handleC, vector_handleB, 0, NULL, NULL);
  66. starpu_data_cpy(vector_handleD, vector_handleC, 0, NULL, NULL);
  67. starpu_data_cpy(vector_handleE, vector_handleD, 0, NULL, NULL);
  68. starpu_data_cpy(vector_handleF, vector_handleE, 0, NULL, NULL);
  69. /* StarPU does not need to manipulate the array anymore so we can stop
  70. * monitoring it */
  71. /* free them */
  72. starpu_data_unregister(vector_handleA);
  73. starpu_data_unregister(vector_handleB);
  74. starpu_data_unregister(vector_handleC);
  75. starpu_data_unregister(vector_handleD);
  76. starpu_data_unregister(vector_handleE);
  77. starpu_data_unregister(vector_handleF);
  78. /* check if computation is correct */
  79. int try = 1;
  80. for (j = 0; j < NX; ++j)
  81. if (A[j] != F[j])
  82. {
  83. FPRINTF(stderr, "Fail A %f != F %f \n", A[j], F[j]);
  84. try = 0;
  85. }
  86. /* free last vectors */
  87. starpu_free_flags(A, NX*sizeof(double), STARPU_MALLOC_COUNT);
  88. starpu_free_flags(F, NX*sizeof(double), STARPU_MALLOC_COUNT);
  89. /* terminate StarPU, no task can be submitted after */
  90. starpu_shutdown();
  91. if(try)
  92. FPRINTF(stderr, "TEST SUCCESS\n");
  93. else
  94. FPRINTF(stderr, "TEST FAIL\n");
  95. return (try ? EXIT_SUCCESS : EXIT_FAILURE);
  96. enodev:
  97. return STARPU_TEST_SKIPPED;
  98. enoent:
  99. return STARPU_TEST_SKIPPED;
  100. }