|
'ElMo-Knock'
|
00001 #include <string.h> 00002 #include "mpi_utils.h" 00003 #include "util.h" 00004 00005 00006 00007 int mpi_bcast_vector_of_strings(vector<string> &vector_of_strings) { 00008 00009 int s_size; 00010 char *sz; 00011 int proc_id=0,nump=1; 00012 00013 util::get_proc_id_nump(proc_id,nump); 00014 00015 #ifdef PARALLEL 00016 00017 int vec_size; 00018 if (proc_id==0) 00019 vec_size=vector_of_strings.size(); 00020 MPI_Bcast(&vec_size,1,MPI_INT, 0, MPI_COMM_WORLD); 00021 if (proc_id!=0) 00022 vector_of_strings.resize(vec_size); 00023 00024 for (int i=0;i<vec_size;i++) { 00025 00026 if (proc_id==0) { 00027 //convert vector_ 00028 string s = vector_of_strings[i]; 00029 00030 sz = new char[s.length() + 1]; 00031 s_size=s.length(); 00032 sz[s_size]='\0'; 00033 strcpy(sz, s.c_str()); 00034 } 00035 MPI_Bcast(&s_size,1,MPI_INT,0,MPI_COMM_WORLD); 00036 if (proc_id!=0) 00037 sz = new char[s_size + 1]; 00038 00039 MPI_Bcast(&sz[0],s_size+1,MPI_CHAR,0,MPI_COMM_WORLD); 00040 00041 if (proc_id!=0) { 00042 string tmp_s(sz); 00043 vector_of_strings[i]=tmp_s; 00044 } 00045 } 00046 00047 #endif 00048 } 00049 00050 00051 int mpi_bcast_string(std::string &ss) { 00052 00053 unsigned int len; 00054 int proc_id=0,nump=1; 00055 util::get_proc_id_nump(proc_id,nump); 00056 if (proc_id==0) 00057 len = ss.length(); 00058 mpi_bcast_scalar(len); 00059 if (proc_id!=0) 00060 ss.resize(len); 00061 //if ( v.length() < len ) v.insert(v.end(),(size_t)(len-v.length()), ' ' ); 00062 //else if ( v.length() > len ) v.erase( len, v.length()-len ); 00063 #ifdef PARALLEL 00064 MPI_Bcast( const_cast<char *>(ss.data()), len, MPI_CHAR, 0, MPI_COMM_WORLD); 00065 #endif 00066 00067 } 00068