File: fbtl_ime.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 (183 lines) | stat: -rw-r--r-- 6,214 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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
 * Copyright (c) 2018      DataDirect Networks. All rights reserved.
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 */

#include "ompi_config.h"
#include "mpi.h"

#include "ompi/mca/fbtl/fbtl.h"
#include "ompi/mca/fbtl/base/base.h"
#include "ompi/mca/fbtl/ime/fbtl_ime.h"

/*
 * *******************************************************************
 * ************************ actions structure ************************
 * *******************************************************************
 */
static mca_fbtl_base_module_1_0_0_t ime =  {
    mca_fbtl_ime_module_init,     /* initialise after being selected */
    mca_fbtl_ime_module_finalize, /* close a module on a communicator */
    mca_fbtl_ime_preadv,          /* blocking read */
    mca_fbtl_ime_ipreadv,         /* non-blocking read*/
    mca_fbtl_ime_pwritev,         /* blocking write */
    mca_fbtl_ime_ipwritev,        /* non-blocking write */
    mca_fbtl_ime_progress,        /* module specific progress */
    mca_fbtl_ime_request_free,     /* free module specific data items on the request */
    mca_fbtl_base_check_atomicity  /* check whether atomicity is supported on this fs */};
/*
 * *******************************************************************
 * ************************* structure ends **************************
 * *******************************************************************
 */

int mca_fbtl_ime_component_init_query(bool enable_progress_threads,
                                      bool enable_mpi_threads)
{
    /* Nothing to do */
   return OMPI_SUCCESS;
}

struct mca_fbtl_base_module_1_0_0_t *
mca_fbtl_ime_component_file_query (ompio_file_t *fh, int *priority)
{
   *priority = mca_fbtl_ime_priority;

    /* Do the same as the FS component:
       Only return a non-null component if IME
       can handle the IO operations. */
    if (IME == fh->f_fstype) {
        if (*priority < FBTL_IME_INCREASED_PRIORITY) {
            *priority = FBTL_IME_INCREASED_PRIORITY;
        }
        return &ime;
    }

   return NULL;
}

int mca_fbtl_ime_component_file_unquery (ompio_file_t *file)
{
   /* This function might be needed for some purposes later. for now it
    * does not have anything to do since there are no steps which need
    * to be undone if this module is not selected */

   return OMPI_SUCCESS;
}

int mca_fbtl_ime_module_init (ompio_file_t *file)
{
    return OMPI_SUCCESS;
}


int mca_fbtl_ime_module_finalize (ompio_file_t *file)
{
    return OMPI_SUCCESS;
}

bool mca_fbtl_ime_progress ( mca_ompio_request_t *req)
{
    int i=0, lcount=0, ret_code=0;
    mca_fbtl_ime_request_data_t *data=(mca_fbtl_ime_request_data_t *)req->req_data;

    /* Go through all the requests in the current batch to check
     * if they have finished. */
    for (i=data->aio_first_active_req; i < data->aio_last_active_req; i++ ) {
        if ( data->aio_req_status[i] == FBTL_IME_REQ_CLOSED ) {
            lcount++;
        }
        else if ( data->aio_req_status[i] >= 0 ) {
            /* request has finished */
            data->aio_open_reqs--;
            lcount++;
            data->aio_total_len += data->aio_req_status[i];
            data->aio_req_status[i] = FBTL_IME_REQ_CLOSED;
        }
        else if ( data->aio_req_status[i] == FBTL_IME_REQ_ERROR ) {
            /* an error occurred. */
            data->aio_open_reqs--;
            lcount++;
            data->aio_req_fail_count++;
            data->aio_req_status[i] = FBTL_IME_REQ_CLOSED;
        }
        else {
            /* not yet done */
        }
    }

    /* In case the current batch of requests terminated, exit if an error
     * happened for any request.
     */
    if ( data->aio_req_fail_count > 0 &&
         lcount == data->aio_last_active_req - data->aio_first_active_req ) {
        goto error_exit;
    }

    /* In case some requests are pending, and no error happened in any of the
     * previous requests, then the next batch of operations should be prepared.
     */
    if ( (lcount == data->aio_req_chunks) && (0 != data->aio_open_reqs) ) {

        /* prepare the next batch of operations */
        data->aio_first_active_req = data->aio_last_active_req;
        if ( (data->aio_req_count-data->aio_last_active_req) > data->aio_req_chunks ) {
            data->aio_last_active_req += data->aio_req_chunks;
        }
        else {
            data->aio_last_active_req = data->aio_req_count;
        }

        /* Send the requests. */
        for ( i=data->aio_first_active_req; i< data->aio_last_active_req; i++ ) {
            if ( FBTL_IME_READ == data->aio_req_type &&
                 ime_native_aio_read(&data->aio_reqs[i]) < 0 ) {
                opal_output(1, "mca_fbtl_ime_progress: error in aio_read()");
                data->aio_req_status[i] = FBTL_IME_REQ_ERROR;
                data->aio_last_active_req = i + 1;
                break;
            }
            else if ( FBTL_IME_WRITE == data->aio_req_type &&
                      ime_native_aio_write(&data->aio_reqs[i]) < 0 ) {
                opal_output(1, "mca_fbtl_ime_progress: error in aio_write()");
                data->aio_req_status[i] = FBTL_IME_REQ_ERROR;
                data->aio_last_active_req = i + 1;
                break;
            }
        }
    }

    if ( 0 == data->aio_open_reqs ) {
        /* all pending operations are finished for this request */
        req->req_ompi.req_status.MPI_ERROR = OMPI_SUCCESS;
        req->req_ompi.req_status._ucount = data->aio_total_len;
        return true;
    }
    return false;

error_exit:
    req->req_ompi.req_status.MPI_ERROR = OMPI_ERROR;
    req->req_ompi.req_status._ucount = data->aio_total_len;
    return true;
}

void mca_fbtl_ime_request_free ( mca_ompio_request_t *req)
{
    /* Free the fbtl specific data structures */
    mca_fbtl_ime_request_data_t *data=(mca_fbtl_ime_request_data_t *)req->req_data;
    if (NULL != data) {
        free (data->allocated_data);
        free (data);
        req->req_data = NULL;
    }
}

void mca_fbtl_ime_complete_cb  (struct ime_aiocb *aiocb, int err, ssize_t bytes)
{
    ssize_t *req_status = (ssize_t *) aiocb->user_context;
    *req_status = err == 0 ? bytes : FBTL_IME_REQ_ERROR;
}