Advertisement
randomaccessiterator

Untitled

Sep 7th, 2011
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.97 KB | None | 0 0
  1. // Subdomain data
  2. int L; // number of points in the subdomain
  3. int G; // number of global points  G = \sum L for all subdomains
  4. vector<double> u(L), v(L), w(L);
  5. vector<int> global_indices(L);
  6.  
  7.  
  8. // MPI datatype for single field in memory
  9. MPI_Datatype memory_t;
  10. MPI_Type_contiguous( L, MPI_DOUBLE, &memory_t );
  11.  
  12. // MPI datatype for single field in file
  13. MPI_Datatype file_t;
  14. MPI_Type_create_indexed_block(
  15.  L, //  count
  16.  1, //  blocklength
  17.  &global_indices[0], //  array_of_displacements
  18.  MPI_DOUBLE,
  19.  &file_t
  20. );
  21.  
  22.  
  23. //  +--------------+
  24. //  |   Option 1   |
  25. //  +--------------+
  26. //   Repeated Write_all for each field
  27.  
  28. /* file open etc. */
  29.  
  30. // Set view and output for each fields in order
  31.  
  32. MPI_File_set_view( fh, 0, MPI_DOUBLE, file_t, "native", MPI_INFO_NULL    );
  33. MPI_File_write_all(   fh, &u[0], 1, memory_t, MPI_STATUS_IGNORE  );
  34. MPI_File_set_view( fh, G, MPI_DOUBLE, file_t, "native", MPI_INFO_NULL    );
  35. MPI_File_write_all(   fh, &v[0], 1, memory_t, MPI_STATUS_IGNORE  );
  36. MPI_File_set_view( fh, 2*G, MPI_DOUBLE, file_t, "native", MPI_INFO_NULL  );
  37. MPI_File_write_all(   fh, &w[0], 1, memory_t, MPI_STATUS_IGNORE  );
  38.  
  39.  
  40. //  +--------------+
  41. //  |   Option 2   |
  42. //  +--------------+
  43. //  Single shot collective I/O for all 3 fields
  44.  
  45. // Memory type aggregating all fields
  46. MPI_Datatype all_memory_t;
  47. int blocklengths[3];
  48. MPI_Aint disps[3];
  49. disps[0] = MPI_Get_address( &u[0], &disps[0] );
  50. disps[1] = MPI_Get_address( &v[0], &disps[1] );
  51. disps[2] = MPI_Get_address( &w[0], &disps[2] );
  52.  
  53. MPI_Type_create_hindexed(
  54.   3,
  55.   blocklengths,
  56.   disps,
  57.   memory_t,
  58.   &all_memory_t
  59. );
  60.  
  61. // file type
  62. int file_disps[] = { 0, G, 2*G };
  63. MPI_Datatype all_file_t;
  64. MPI_Type_create_indexed_block(
  65.  3,
  66.  1,
  67.  file_disps,
  68.  file_t,
  69.  &all_file_t
  70. );
  71.  
  72.  
  73. /* file open etc. */
  74. // Set one shot view
  75. MPI_File_set_view( fh, 0, MPI_DOUBLE, all_file_t, "native", MPI_INFO_NULL );
  76. // Output all at once
  77. MPI_File_write_all( fh, MPI_BOTTOM, 1, all_memory_t, MPI_STATUS_IGNORE);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement