Matrix.xmptype.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* -*- mode: c++; c-file-style: "engine"; c-basic-offset: 4; indent-tabs-mode: nil -*- */
  2. /**
  3. * @file
  4. * @brief Matrix parameter wrapper for XMP
  5. *
  6. *
  7. *
  8. * 2012-01-12
  9. *
  10. */
  11. #ifndef MATRIX_XMP_TYPE_HH
  12. #define MATRIX_XMP_TYPE_HH 1
  13. #include <stdlib.h>
  14. #include <stdbool.h>
  15. #include <mpi.h>
  16. typedef double XMP_Matrix; /* Declaration of parameter type in XMP ( XMP_type )*/
  17. typedef double* Matrix; /* Declaration of parameter type for import/export functions (type) */
  18. /* */
  19. static MPI_Datatype Matrix_MPI_Type()
  20. {
  21. return MPI_DOUBLE;
  22. }
  23. // param_import / export definition for types that need data distribution in XMP
  24. static bool Matrix_import(Matrix param, char* filename, const MPI_Datatype motif, const int size)
  25. {
  26. int ack;
  27. MPI_File fh;
  28. MPI_Status status;
  29. ack = MPI_File_open(MPI_COMM_WORLD,filename,MPI_MODE_RDONLY,MPI_INFO_NULL,&fh);
  30. if (ack != MPI_ERR_NO_SUCH_FILE)
  31. {
  32. MPI_File_set_view(fh, 0, MPI_DOUBLE, motif,"native", MPI_INFO_NULL);
  33. MPI_File_read_all(fh, param, size, MPI_DOUBLE, &status);
  34. MPI_File_close(&fh);
  35. return true;
  36. }
  37. MPI_File_close(&fh);
  38. return false;
  39. }
  40. static bool Matrix_export(const Matrix param, char* filename, const MPI_Datatype motif, const int size, MPI_Comm Communicator)
  41. {
  42. int ack;
  43. MPI_File fh;
  44. MPI_Status status;
  45. ack = MPI_File_open(Communicator,filename,MPI_MODE_WRONLY | MPI_MODE_CREATE,MPI_INFO_NULL,&fh);
  46. if (ack != MPI_ERR_NO_SUCH_FILE)
  47. {
  48. MPI_File_set_view(fh, 0, MPI_DOUBLE, motif ,"native", MPI_INFO_NULL);
  49. MPI_File_write_all(fh, param, size, MPI_DOUBLE, &status);
  50. MPI_File_close(&fh);
  51. return true;
  52. }
  53. MPI_File_close(&fh);
  54. return false;
  55. }
  56. #endif