Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Subdomain data
- int L; // number of points in the subdomain
- int G; // number of global points G = \sum L for all subdomains
- vector<double> u(L), v(L), w(L);
- vector<int> global_indices(L);
- // MPI datatype for single field in memory
- MPI_Datatype memory_t;
- MPI_Type_contiguous( L, MPI_DOUBLE, &memory_t );
- // MPI datatype for single field in file
- MPI_Datatype file_t;
- MPI_Type_create_indexed_block(
- L, // count
- 1, // blocklength
- &global_indices[0], // array_of_displacements
- MPI_DOUBLE,
- &file_t
- );
- // +--------------+
- // | Option 1 |
- // +--------------+
- // Repeated Write_all for each field
- /* file open etc. */
- // Set view and output for each fields in order
- MPI_File_set_view( fh, 0, MPI_DOUBLE, file_t, "native", MPI_INFO_NULL );
- MPI_File_write_all( fh, &u[0], 1, memory_t, MPI_STATUS_IGNORE );
- MPI_File_set_view( fh, G, MPI_DOUBLE, file_t, "native", MPI_INFO_NULL );
- MPI_File_write_all( fh, &v[0], 1, memory_t, MPI_STATUS_IGNORE );
- MPI_File_set_view( fh, 2*G, MPI_DOUBLE, file_t, "native", MPI_INFO_NULL );
- MPI_File_write_all( fh, &w[0], 1, memory_t, MPI_STATUS_IGNORE );
- // +--------------+
- // | Option 2 |
- // +--------------+
- // Single shot collective I/O for all 3 fields
- // Memory type aggregating all fields
- MPI_Datatype all_memory_t;
- int blocklengths[3];
- MPI_Aint disps[3];
- disps[0] = MPI_Get_address( &u[0], &disps[0] );
- disps[1] = MPI_Get_address( &v[0], &disps[1] );
- disps[2] = MPI_Get_address( &w[0], &disps[2] );
- MPI_Type_create_hindexed(
- 3,
- blocklengths,
- disps,
- memory_t,
- &all_memory_t
- );
- // file type
- int file_disps[] = { 0, G, 2*G };
- MPI_Datatype all_file_t;
- MPI_Type_create_indexed_block(
- 3,
- 1,
- file_disps,
- file_t,
- &all_file_t
- );
- /* file open etc. */
- // Set one shot view
- MPI_File_set_view( fh, 0, MPI_DOUBLE, all_file_t, "native", MPI_INFO_NULL );
- // Output all at once
- MPI_File_write_all( fh, MPI_BOTTOM, 1, all_memory_t, MPI_STATUS_IGNORE);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement