mpiu_external32.c 4.2 KB
Newer Older
1
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*  (C) 2012 by Argonne National Laboratory.
 *      See COPYRIGHT in top-level directory.
 */

#include "mpioimpl.h"
#include "mpiu_external32.h"

#ifdef HAVE_WEAK_SYMBOLS
/* Include mapping from MPI->PMPI */
#define MPIO_BUILD_PROFILING
#include "mpioprof.h"
#endif

int MPIU_write_external32_conversion_fn (void *userbuf, MPI_Datatype datatype,
        int count, void *filebuf)
{
    int position_i = 0;
    MPI_Aint position = 0;
    MPI_Aint bytes = 0;
    int mpi_errno = MPI_SUCCESS;
    int is_contig = 0;

24
    ADIOI_Datatype_iscontig(datatype, &is_contig);
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
    mpi_errno = MPI_Pack_external_size("external32", count, datatype, &bytes);
    if (mpi_errno != MPI_SUCCESS)
        goto fn_exit;

    if (is_contig)
    {
        mpi_errno = MPI_Pack_external("external32", userbuf, count,
                datatype, filebuf, bytes, &position);
        if (mpi_errno != MPI_SUCCESS)
            goto fn_exit;
    }
    else
    {
        void *tmp_buf = NULL;
        tmp_buf = ADIOI_Malloc(bytes); 
        if (!tmp_buf)
        {
            mpi_errno = MPI_ERR_NO_MEM;
            goto fn_exit;
        }

        mpi_errno = MPI_Pack_external("external32", userbuf, count,
                datatype, tmp_buf, bytes, &position);
        if (mpi_errno != MPI_SUCCESS)
        {
            ADIOI_Free(tmp_buf);
            goto fn_exit;
        }

        mpi_errno = MPI_Unpack(tmp_buf, bytes, &position_i, filebuf, count,
                datatype, MPI_COMM_WORLD);
        if (mpi_errno != MPI_SUCCESS)
        {
            ADIOI_Free(tmp_buf);
            goto fn_exit;
        }

        ADIOI_Free(tmp_buf);
    }
fn_exit:
    return mpi_errno;
}

int MPIU_read_external32_conversion_fn(void *userbuf, MPI_Datatype datatype,
        int count, void *filebuf)
{
    int position_i = 0;
    MPI_Aint position = 0;
    MPI_Aint bytes = 0;
    int mpi_errno = MPI_SUCCESS;
    int is_contig = 0;

77
    ADIOI_Datatype_iscontig(datatype, &is_contig);
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
    mpi_errno = MPI_Pack_external_size("external32", count, datatype, &bytes);
    if (mpi_errno != MPI_SUCCESS)
        goto fn_exit;

    if (is_contig)
    {
        mpi_errno = MPI_Unpack_external("external32", filebuf, bytes,
                &position, userbuf, count,  datatype);
        if (mpi_errno != MPI_SUCCESS)
            goto fn_exit;
    }
    else
    {
        void *tmp_buf = NULL;
        tmp_buf = ADIOI_Malloc(bytes); 
        if (!tmp_buf)
        {
            mpi_errno = MPI_ERR_NO_MEM;
            goto fn_exit;
        }

        mpi_errno = MPI_Pack(filebuf, count, datatype, tmp_buf, bytes,
                &position_i, MPI_COMM_WORLD);
        if (mpi_errno != MPI_SUCCESS)
        {
            ADIOI_Free(tmp_buf);
            goto fn_exit;
        }

        mpi_errno = MPI_Unpack_external("external32", tmp_buf, bytes,
                &position, userbuf, count, datatype);
        if (mpi_errno != MPI_SUCCESS)
        {
            ADIOI_Free(tmp_buf);
            goto fn_exit;
        }

        ADIOI_Free(tmp_buf);
    }
fn_exit:
    return mpi_errno;
}
int MPIU_datatype_full_size(MPI_Datatype datatype, MPI_Aint *size)
{
    int error_code = MPI_SUCCESS;
    MPI_Aint extent = 0;
    MPI_Aint true_extent = 0;
    MPI_Aint true_lb = 0;

    error_code = MPI_Type_get_true_extent(datatype, &true_lb, &true_extent);
    if (error_code != MPI_SUCCESS)
        goto fn_exit;

    *size = true_extent;
fn_exit:
    return error_code;
}

136
137
138
139
/* given a buffer, count, and datatype, return an apropriately allocated, sized
 * and external32-formatted buffer, suitable for handing off to a subsequent
 * write routine.  Caller is responsible for freeing 'newbuf' */
int MPIU_external32_buffer_setup(void * buf, int count, MPI_Datatype type, void **newbuf)
140
141
142
143
144
145
146
147
148
149
{

    MPI_Aint datatype_size=0, bytes=0;
    int error_code;

    error_code = MPIU_datatype_full_size(type, &datatype_size);
    if (error_code != MPI_SUCCESS)
	return error_code;

    bytes = datatype_size * count;
150
    *newbuf = ADIOI_Malloc(bytes);
151

152
    error_code = MPIU_write_external32_conversion_fn(buf, type, count, *newbuf);
153
154
155
156
157
158
159
160
161
162
163
    if (error_code != MPI_SUCCESS) {
	ADIOI_Free(newbuf);
	return error_code;
    }
    return MPI_SUCCESS;
}


/* 
 * vim: ts=8 sts=4 sw=4 noexpandtab 
 */