From 5376b9056bf7465adcbfbe9709d76d6c950864e0 Mon Sep 17 00:00:00 2001 From: sjplimp Date: Fri, 8 Nov 2013 20:32:38 +0000 Subject: [PATCH] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@11003 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- src/comm.cpp | 36 ++++++++++++++++++++++++++++++++++++ src/comm.h | 1 + 2 files changed, 37 insertions(+) diff --git a/src/comm.cpp b/src/comm.cpp index be6970e4d9..1bb82bd8c4 100644 --- a/src/comm.cpp +++ b/src/comm.cpp @@ -1597,6 +1597,42 @@ int Comm::read_lines_from_file(FILE *fp, int nlines, int maxline, char *buf) return 0; } +/* ---------------------------------------------------------------------- + proc 0 reads Nlines from file into buf and bcasts buf to all procs + caller allocates buf to max size needed + each line is terminated by newline, even if last line in file is not + return 0 if successful, 1 if get EOF error before read is complete +------------------------------------------------------------------------- */ + +int Comm::read_lines_from_file_universe(FILE *fp, int nlines, int maxline, + char *buf) +{ + int m; + + int me_universe = universe->me; + MPI_Comm uworld = universe->uworld; + + if (me_universe == 0) { + m = 0; + for (int i = 0; i < nlines; i++) { + if (!fgets(&buf[m],maxline,fp)) { + m = 0; + break; + } + m += strlen(&buf[m]); + } + if (m) { + if (buf[m-1] != '\n') strcpy(&buf[m++],"\n"); + m++; + } + } + + MPI_Bcast(&m,1,MPI_INT,0,uworld); + if (m == 0) return 1; + MPI_Bcast(buf,m,MPI_CHAR,0,uworld); + return 0; +} + /* ---------------------------------------------------------------------- realloc the size of the send buffer as needed with BUFFACTOR and bufextra if flag = 1, realloc diff --git a/src/comm.h b/src/comm.h index 2dfda26d75..e667ba2c32 100644 --- a/src/comm.h +++ b/src/comm.h @@ -66,6 +66,7 @@ class Comm : protected Pointers { void ring(int, int, void *, int, void (*)(int, char *), // ring comm void *, int self = 1); int read_lines_from_file(FILE *, int, int, char *); // read/bcast file lines + int read_lines_from_file_universe(FILE *, int, int, char *); virtual void set(int, char **); // set communication style void set_processors(int, char **); // set 3d processor grid attributes