disk_copy.c 3.9 KB

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