File: mpio_file.c

package info (click to toggle)
openmpi 2.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 99,912 kB
  • ctags: 55,589
  • sloc: ansic: 525,999; f90: 18,307; makefile: 12,062; sh: 6,583; java: 6,278; asm: 3,515; cpp: 2,227; perl: 2,136; python: 1,350; lex: 734; fortran: 52; tcl: 12
file content (90 lines) | stat: -rw-r--r-- 2,373 bytes parent folder | download | duplicates (2)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
/*
 *
 *   Copyright (C) 2004 University of Chicago.
 *   See COPYRIGHT notice in top-level directory.
 */

#include "mpioimpl.h"

/* Hooks for allocation of MPI_File handles.
 *
 * Three functions are used in ROMIO for allocation/deallocation
 * of MPI_File structures:
 * - MPIO_File_create(size)
 * - MPIO_File_resolve(mpi_fh)
 * - MPIO_File_free(mpi_fh)
 *
 */

MPI_File MPIO_File_create(int size)
{
    MPI_File mpi_fh;

    mpi_fh = (MPI_File) ADIOI_Calloc(size,1);
    return mpi_fh;
}

ADIO_File MPIO_File_resolve(MPI_File mpi_fh)
{
    return mpi_fh;
}

void MPIO_File_free(MPI_File *mpi_fh)
{
    ADIOI_Free(*mpi_fh);
    *mpi_fh = MPI_FILE_NULL;
}

extern ADIO_File *ADIOI_Ftable;
extern int ADIOI_Ftable_ptr;
extern int ADIOI_Ftable_max;

MPI_File MPIO_File_f2c(MPI_Fint fh)
{
#ifndef INT_LT_POINTER
    return (MPI_File) ((void *) fh);
    /* the extra cast is to get rid of a compiler warning on Exemplar.
       The warning is because MPI_File points to a structure containing
       longlongs, which may be 8-byte aligned. But MPI_Fint itself
       may not be 8-byte aligned.*/
#else
    if (!fh) return MPI_FILE_NULL;
    if ((fh < 0) || (fh > ADIOI_Ftable_ptr)) {
	FPRINTF(stderr, "MPI_File_f2c: Invalid file handle\n");
	/* there is no way to return an error from MPI_File_f2c */
	return MPI_FILE_NULL;
    }
    return ADIOI_Ftable[fh];
#endif
}

MPI_Fint MPIO_File_c2f(MPI_File fh)
{
#ifndef INT_LT_POINTER
    return (MPI_Fint) fh;
#else
    int i;

    if ((fh <= (MPI_File) 0) || (fh->cookie != ADIOI_FILE_COOKIE))
	return (MPI_Fint) 0;
    if (!ADIOI_Ftable) {
	ADIOI_Ftable_max = 1024;
	ADIOI_Ftable = (MPI_File *)
	    ADIOI_Malloc(ADIOI_Ftable_max*sizeof(MPI_File));
        ADIOI_Ftable_ptr = 0;  /* 0 can't be used though, because
                                  MPI_FILE_NULL=0 */
	for (i=0; i<ADIOI_Ftable_max; i++) ADIOI_Ftable[i] = MPI_FILE_NULL;
    }
    if (ADIOI_Ftable_ptr == ADIOI_Ftable_max-1) {
	ADIOI_Ftable = (MPI_File *) ADIOI_Realloc(ADIOI_Ftable,
                           (ADIOI_Ftable_max+1024)*sizeof(MPI_File));
	for (i=ADIOI_Ftable_max; i<ADIOI_Ftable_max+1024; i++)
	    ADIOI_Ftable[i] = MPI_FILE_NULL;
	ADIOI_Ftable_max += 1024;
    }
    ADIOI_Ftable_ptr++;
    ADIOI_Ftable[ADIOI_Ftable_ptr] = fh;
    return (MPI_Fint) ADIOI_Ftable_ptr;
#endif
}