strlen
バッファサイズに使用できます
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
int main(int argc,char *argv[])
{
int namelen, numprocs, rank = 7;
char processor_name[MPI_MAX_PROCESSOR_NAME];
MPI_Init(&argc,&argv);
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
MPI_Get_processor_name(processor_name,&namelen);
MPI_Status status;
MPI_File fh;
string test;
const char* buf[100];
string g = "test" + to_string(rank) + ".txt";
MPI_File_open(MPI_COMM_SELF, g.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY,MPI_INFO_NULL,&fh);
for (int i=0; i < 100; i++){
test = to_string(i) + "\n";
buf[i] = test.c_str();
MPI_File_write(fh, buf[i], strlen(buf[i]), MPI_CHAR, &status);
}
MPI_File_close(&fh);
MPI_Finalize();
return 0;
}
注意してくださいMPI_File_write(fh, buf[i], strlen(buf[i]), MPI_CHAR, &status);
それが役立つことを願っています。