1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
/*
*
* Copyright (C) 1997 University of Chicago.
* See COPYRIGHT notice in top-level directory.
*/
#include "adio.h"
#include "adio_extern.h"
/* this used to be implemented in every file system as an fcntl. It makes
* deferred open easier if we know ADIO_Fcntl will always need a file to really
* be open. set_view doesn't modify anything related to the open files.
*/
void ADIO_Set_view(ADIO_File fd, ADIO_Offset disp, MPI_Datatype etype,
MPI_Datatype filetype, MPI_Info info, int *error_code)
{
int combiner, i, j, k, err, filetype_is_contig;
MPI_Datatype copy_etype, copy_filetype;
ADIOI_Flatlist_node *flat_file;
/* free copies of old etypes and filetypes and delete flattened
version of filetype if necessary */
MPI_Type_get_envelope(fd->etype, &i, &j, &k, &combiner);
if (combiner != MPI_COMBINER_NAMED) MPI_Type_free(&(fd->etype));
ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);
if (!filetype_is_contig) ADIOI_Delete_flattened(fd->filetype);
MPI_Type_get_envelope(fd->filetype, &i, &j, &k, &combiner);
if (combiner != MPI_COMBINER_NAMED) MPI_Type_free(&(fd->filetype));
/* set new info */
ADIO_SetInfo(fd, info, &err);
/* set new etypes and filetypes */
MPI_Type_get_envelope(etype, &i, &j, &k, &combiner);
if (combiner == MPI_COMBINER_NAMED) fd->etype = etype;
else {
MPI_Type_contiguous(1, etype, ©_etype);
MPI_Type_commit(©_etype);
fd->etype = copy_etype;
}
MPI_Type_get_envelope(filetype, &i, &j, &k, &combiner);
if (combiner == MPI_COMBINER_NAMED)
fd->filetype = filetype;
else {
MPI_Type_contiguous(1, filetype, ©_filetype);
MPI_Type_commit(©_filetype);
fd->filetype = copy_filetype;
ADIOI_Flatten_datatype(fd->filetype);
/* this function will not flatten the filetype if it turns out
to be all contiguous. */
}
MPI_Type_size_x(fd->etype, &(fd->etype_size));
fd->disp = disp;
/* reset MPI-IO file pointer to point to the first byte that can
be accessed in this view. */
ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);
if (filetype_is_contig) fd->fp_ind = disp;
else {
flat_file = ADIOI_Flatlist;
while (flat_file->type != fd->filetype)
flat_file = flat_file->next;
for (i=0; i<flat_file->count; i++) {
if (flat_file->blocklens[i]) {
fd->fp_ind = disp + flat_file->indices[i];
break;
}
}
}
*error_code = MPI_SUCCESS;
}
|