使用aio_write异步输出到文件

时间:2018-06-09 14:23:45

标签: c asynchronous aio-write

作为大型项目的一部分,我想将以下输出方法更改为两个文件,并使用" aio.h"的

#include <stdio.h>
#include <math.h>
#include <getopt.h>
#include <stdlib.h>
#include <sys/time.h>
#include "cblas.h"
#include "omp.h"
FILE        *output1, *output2;
output1 = fopen("spacetime1.out", "w");
output2 = fopen("omega.out", "w");
double      *u, *uplus, *sigma, *omega, *omega1;

int main {
 ...
            fprintf(output1, "%ld\t", it);
            for (i = 0; i < n; i++) {
                fprintf(output1, "%19.15f", u[i]);
            }
            fprintf(output1, "\n");

            time = (double)it * dt;
            fprintf(output2, "%ld\t", it);

            for (i = 0; i < n; i++) {
                omega[i] = 2.0 * M_PI * omega1[i] / (time - ttransient * dt);
                fprintf(output2, "%19.15f", omega[i]);
            }
            fprintf(output2, "\n");
}

我正在努力定义结构,以及如何每次将u [i]复制到缓冲区?有什么帮助吗?

       struct aiocb aio;
        aio.aio_offset = 0;
        aio.aio_fildes = outFile1;
        aio.aio_reqprio = 0;
        aio.aio_buf = memcpy(buff, &u[i], 1000);
        aio.aio_nbytes = 1000;
        aio.aio_sigvent.sigev_notify = SIGEV_NONE;

0 个答案:

没有答案