disk_copy.c 4.1 KB

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