File: fbtl_pvfs2_preadv.c

package info (click to toggle)
openmpi 5.0.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 202,312 kB
  • sloc: ansic: 612,441; makefile: 42,495; sh: 11,230; javascript: 9,244; f90: 7,052; java: 6,404; perl: 5,154; python: 1,856; lex: 740; fortran: 61; cpp: 20; tcl: 12
file content (149 lines) | stat: -rw-r--r-- 4,047 bytes parent folder | download | duplicates (4)
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
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
 * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
 *                         University Research and Technology
 *                         Corporation.  All rights reserved.
 * Copyright (c) 2004-2011 The University of Tennessee and The University
 *                         of Tennessee Research Foundation.  All rights
 *                         reserved.
 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
 *                         University of Stuttgart.  All rights reserved.
 * Copyright (c) 2004-2005 The Regents of the University of California.
 *                         All rights reserved.
 * Copyright (c) 2008-2014 University of Houston. All rights reserved.
 * Copyright (c) 2017-2018 Research Organization for Information Science
 *                         and Technology (RIST). All rights reserved.
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 */

/* This code is based on the PVFS2 ADIO module in ROMIO
 *   Copyright (C) 1997 University of Chicago.
 *   See COPYRIGHT notice in top-level directory.
 */

#include "ompi_config.h"
#include "fbtl_pvfs2.h"

#include "mpi.h"
#include <unistd.h>
#include "ompi/constants.h"
#include "ompi/mca/fbtl/fbtl.h"

ssize_t  mca_fbtl_pvfs2_preadv (ompio_file_t *fh)
{
    int i;
    int ret;
    size_t k;
    int merge = 0;
    char *merge_buf = NULL;
    size_t merge_length = 0;
    OMPI_MPI_OFFSET_TYPE merge_offset = 0;
    PVFS_sysresp_io resp_io;
    PVFS_Request file_req;
    PVFS_Request mem_req;
    mca_fs_pvfs2 *pvfs2_fs;
    ssize_t total_bytes_read=0;

    pvfs2_fs = (mca_fs_pvfs2 *)fh->f_fs_ptr;

    if (NULL == fh->f_io_array) {
        return OMPI_ERROR;
    }

    for (i=0 ; i<fh->f_num_of_io_entries ; i++) {
	if (fh->f_num_of_io_entries != i+1) {
	    if (((OMPI_MPI_OFFSET_TYPE)fh->f_io_array[i].offset +
		 (ptrdiff_t)fh->f_io_array[i].length) ==
		(OMPI_MPI_OFFSET_TYPE)fh->f_io_array[i+1].offset) {
		if (!merge) {
		    merge_offset = (OMPI_MPI_OFFSET_TYPE)
			fh->f_io_array[i].offset;
		    merge_length = fh->f_io_array[i].length;
		}
		merge_length += fh->f_io_array[i+1].length;
		merge++;
		continue;
	    }
	}
	if (merge) {
	    merge_buf = malloc (merge_length);

	    ret = PVFS_Request_contiguous (merge_length,
					   PVFS_BYTE,
					   &mem_req);
	    if (ret != 0) {
		perror("PVFS_Request_contiguous() error");
		return OMPI_ERROR;
	    }
	    ret = PVFS_Request_contiguous (merge_length,
					   PVFS_BYTE,
					   &file_req);
	    if (ret != 0) {
		perror("PVFS_Request_contiguous() error");
		return OMPI_ERROR;
	    }
	    ret = PVFS_sys_read (pvfs2_fs->object_ref,
				 file_req,
				 merge_offset,
				 merge_buf,
				 mem_req,
				 &(pvfs2_fs->credentials),
				 &resp_io);
	    if (ret != 0) {
		perror("PVFS_sys_write() error");
		return OMPI_ERROR;
	    }
	    total_bytes_read += (ssize_t)resp_io.total_completed;

	    k = 0;
	    while (merge >= 0) {
		memcpy (fh->f_io_array[i-merge].memory_address,
			merge_buf + k,
			fh->f_io_array[i-merge].length);
		k += fh->f_io_array[i-merge].length;
		merge --;
	    }
	    merge = 0;
	    merge_offset = 0;
	    merge_length = 0;
	    if (NULL != merge_buf) {
		free (merge_buf);
		merge_buf = NULL;
	    }
	}
	else {
	    ret = PVFS_Request_contiguous (fh->f_io_array[i].length,
					   PVFS_BYTE,
					   &mem_req);
	    if (ret != 0) {
		perror("PVFS_Request_contiguous() error");
		return OMPI_ERROR;
	    }
	    ret = PVFS_Request_contiguous (fh->f_io_array[i].length,
					   PVFS_BYTE,
					   &file_req);
	    if (ret != 0) {
		perror("PVFS_Request_contiguous() error");
		return OMPI_ERROR;
	    }
	    ret = PVFS_sys_read (pvfs2_fs->object_ref,
				 file_req,
				 (OMPI_MPI_OFFSET_TYPE)
				 fh ->f_io_array[i].offset,
				 fh->f_io_array[i].memory_address,
				 mem_req,
				 &(pvfs2_fs->credentials),
				 &resp_io);
	    if (ret != 0) {
		perror("PVFS_sys_write() error");
		return OMPI_ERROR;
	    }
	    total_bytes_read += (ssize_t)resp_io.total_completed;
	}
    }

    return total_bytes_read;
}