Commit 09f7088f authored by Shen Yu's avatar Shen Yu
Browse files

modified: openmpi-4.1.1/ompi/mpi/c/init.c

	new file:   replayer/Makefile
	new file:   replayer/createMPIComm.cpp
	new file:   replayer/createMPIComm.h
	deleted:    replayer/function_list.h
	modified:   replayer/mpi_player.cpp
	new file:   replayer/read_run.cpp
	new file:   replayer/read_run.h
passed compile with gcc 8.3.1
tested with allreduce
parent 055e7496
......@@ -134,11 +134,8 @@ int MPI_Init(int *argc, char ***argv)
LOGTHIS=true;
// every process set its onw file name with hostname and pid
int namelen;
char HOSTNAME[MPI_MAX_PROCESSOR_NAME];
MPI_Get_processor_name(HOSTNAME, &namelen);
char logfilename[4096];
sprintf(logfilename, "%s/MSGLOG.%s.%d.csv", logfilepath, HOSTNAME, LOGMSGMYID);
sprintf(logfilename, "%s/MSGLOG.%d.csv", logfilepath, LOGMSGMYID);
// if the directory is not existed, make it and open the file
struct stat st = {0};
......@@ -152,7 +149,6 @@ int MPI_Init(int *argc, char ***argv)
LOGMSG0(FUNC_ID, START_TIME, MPI_COMM_WORLD);
const int total_nproc=ompi_comm_size(MPI_COMM_WORLD);
INT_POOL=malloc(total_nproc*2*sizeof(int));
printf("INT_POOL inited\n");
REQ_POOL_SIZE=1024;
REQ_POOL=malloc(1024*sizeof(int));
// end
......
mpi_player: createMPIComm.o read_run.o mpi_player.o
mpicxx -o mpi_player createMPIComm.o read_run.o mpi_player.o
createMPIComm.o: createMPIComm.cpp
mpicxx -c createMPIComm.cpp
read_run.o: read_run.cpp
mpicxx -c read_run.cpp
mpi_player.o: mpi_player.cpp
mpicxx -c mpi_player.cpp
#include <fstream>
#include <map>
#include <set>
#include <vector>
#include <cstring>
#include <mpi.h>
using namespace std;
int createMPIComm(ifstream& inFile, map<int, MPI_Comm>& COMM_LIST)
{
int nComm = 0;
string logline;
set<int> my_comm_ids;
while (getline(inFile, logline))
{
double LOG_CALLTIME, LOG_ENDTIME;
int FUNC_ID, COMM_ID;
sscanf(logline.c_str(), "%lf, %lf, %d, %d", &LOG_CALLTIME, &LOG_ENDTIME, &FUNC_ID, &COMM_ID);
my_comm_ids.insert(COMM_ID);
}
// every process collects numbers of comms of all processes
int nprocs;
MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
vector<int> ncomm(nprocs);
int my_ncomm = my_comm_ids.size();
MPI_Allgather(&my_ncomm, 1, MPI_INT, &ncomm[0], 1, MPI_INT, MPI_COMM_WORLD);
// every process collects all comms from all processes
// every process transform comms from set to sendbuf and
// transform recvbuf to a set which contains unique all comm ids
vector<int> sendbuf(my_comm_ids.begin(), my_comm_ids.end());
vector<int> recvcounts(nprocs);
vector<int> displs(nprocs+1);
int recv_comm_size = 0;
displs[0] = 0;
for(int i = 0; i < nprocs; ++i)
{
recv_comm_size += ncomm[i];
recvcounts[i] = ncomm[i];
if(i > 0)
displs[i] = displs[i - 1] + ncomm[i];
}
displs[nprocs] = recv_comm_size;
vector<int> recvbuf(recv_comm_size);
MPI_Allgatherv(&sendbuf[0], my_ncomm, MPI_INT,
&recvbuf[0], &recvcounts[0], &displs[0], MPI_INT,
MPI_COMM_WORLD);
set<int> all_comm_ids;
for(const auto& id : recvbuf)
all_comm_ids.insert(id);
int myid;
MPI_Comm_rank(MPI_COMM_WORLD, &myid);
// create each comm in all_comm_ids
for(const auto& id: all_comm_ids)
{
MPI_Comm newcomm;
int color = MPI_UNDEFINED;
for(int i = displs[myid]; i < displs[myid+1]; ++i)
{
if(recvbuf[i] == id)
{
color = 0;
break;
}
}
int key = myid;
MPI_Comm_split(MPI_COMM_WORLD, color, key, &newcomm);
COMM_LIST[id] = newcomm;
}
return all_comm_ids.size();
}
int createMPIComm(std::ifstream& inFile, std::map<int, MPI_Comm>& COMM_LIST);
enum MPI_FUNCTION_LIST{
abort,
accumulate,
add_error_class,
add_error_code,
add_error_string,
address,
allgather,
allgatherv,
alloc_mem,
allreduce,
alltoall,
alltoallv,
alltoallw,
attr_delete,
attr_fn,
attr_get,
attr_put,
barrier,
bcast,
bindings.h,
bsend,
bsend_init,
buffer_attach,
buffer_detach,
cancel,
cart_coords,
cart_create,
cartdim_get,
cart_get,
cart_map,
cart_rank,
cart_shift,
cart_sub,
close_port,
comm_accept,
comm_c2f,
comm_call_errhandler,
comm_compare,
comm_connect,
comm_create,
comm_create_errhandler,
comm_create_group,
comm_create_keyval,
comm_delete_attr,
comm_disconnect,
comm_dup,
comm_dup_with_info,
comm_f2c,
comm_free,
comm_free_keyval,
comm_get_attr,
comm_get_errhandler,
comm_get_info,
comm_get_name,
comm_get_parent,
comm_group,
comm_idup,
comm_join,
comm_rank,
comm_remote_group,
comm_remote_size,
comm_set_attr,
comm_set_errhandler,
comm_set_info,
comm_set_name,
comm_size,
comm_spawn,
comm_spawn_multiple,
comm_split,
comm_split_type,
comm_test_inter,
compare_and_swap,
dims_create,
dist_graph_create_adjacent,
dist_graph_create,
dist_graph_neighbors,
dist_graph_neighbors_count,
errhandler_c2f,
errhandler_create,
errhandler_f2c,
errhandler_free,
errhandler_get,
errhandler_set,
error_class,
error_string,
exscan,
fetch_and_op,
file_c2f,
file_call_errhandler,
file_close,
file_create_errhandler,
file_delete,
file_f2c,
file_get_amode,
file_get_atomicity,
file_get_byte_offset,
file_get_errhandler,
file_get_group,
file_get_info,
file_get_position,
file_get_position_shared,
file_get_size,
file_get_type_extent,
file_get_view,
file_iread_all,
file_iread_at_all,
file_iread_at,
file_iread,
file_iread_shared,
file_iwrite_all,
file_iwrite_at_all,
file_iwrite_at,
file_iwrite,
file_iwrite_shared,
file_open,
file_preallocate,
file_read_all_begin,
file_read_all,
file_read_all_end,
file_read_at_all_begin,
file_read_at_all,
file_read_at_all_end,
file_read_at,
file_read,
file_read_ordered_begin,
file_read_ordered,
file_read_ordered_end,
file_read_shared,
file_seek,
file_seek_shared,
file_set_atomicity,
file_set_errhandler,
file_set_info,
file_set_size,
file_set_view,
file_sync,
file_write_all_begin,
file_write_all,
file_write_all_end,
file_write_at_all_begin,
file_write_at_all,
file_write_at_all_end,
file_write_at,
file_write,
file_write_ordered_begin,
file_write_ordered,
file_write_ordered_end,
file_write_shared,
finalize,
finalized,
free_mem,
gather,
gatherv,
get_accumulate,
get_address,
get,
get_count,
get_elements,
get_elements_x,
get_library_version,
get_processor_name,
get_version,
graph_create,
graphdims_get,
graph_get,
graph_map,
graph_neighbors,
graph_neighbors_count,
grequest_complete,
grequest_start,
group_c2f,
group_compare,
group_difference,
group_excl,
group_f2c,
group_free,
group_incl,
group_intersection,
group_range_excl,
group_range_incl,
group_rank,
group_size,
group_translate_ranks,
group_union,
iallgather,
iallgatherv,
iallreduce,
ialltoall,
ialltoallv,
ialltoallw,
ibarrier,
ibcast,
ibsend,
iexscan,
igather,
igatherv,
improbe,
imrecv,
ineighbor_allgather,
ineighbor_allgatherv,
ineighbor_alltoall,
ineighbor_alltoallv,
ineighbor_alltoallw,
info_c2f,
info_create,
info_delete,
info_dup,
info_f2c,
info_free,
info_get,
info_get_nkeys,
info_get_nthkey,
info_get_valuelen,
info_set,
init,
initialized,
init_thread,
intercomm_create,
intercomm_merge,
iprobe,
irecv,
ireduce,
ireduce_scatter_block,
ireduce_scatter,
irsend,
iscan,
iscatter,
iscatterv,
isend,
issend,
is_thread_main,
keyval_create,
keyval_free,
lookup_name,
Makefile.am,
Makefile.in,
message_c2f,
message_f2c,
mprobe,
mrecv,
neighbor_allgather,
neighbor_allgatherv,
neighbor_alltoall,
neighbor_alltoallv,
neighbor_alltoallw,
op_c2f,
op_commutative,
op_create,
open_port,
op_f2c,
op_free,
pack,
pack_external,
pack_external_size,
pack_size,
pcontrol,
probe,
profile,
publish_name,
put,
query_thread,
raccumulate,
recv,
recv_init,
reduce,
reduce_local,
reduce_scatter_block,
reduce_scatter,
register_datarep,
request_c2f,
request_f2c,
request_free,
request_get_status,
rget_accumulate,
rget,
rput,
rsend,
rsend_init,
scan,
scatter,
scatterv,
send,
send_init,
sendrecv,
sendrecv_replace,
ssend,
ssend_init,
startall,
start,
status_c2f,
status_f2c,
status_set_cancelled,
status_set_elements,
status_set_elements_x,
testall,
testany,
test,
test_cancelled,
testsome,
topo_test,
type_c2f,
type_commit,
type_contiguous,
type_create_darray,
type_create_f90_complex,
type_create_f90_integer,
type_create_f90_real,
type_create_hindexed_block,
type_create_hindexed,
type_create_hvector,
type_create_indexed_block,
type_create_keyval,
type_create_resized,
type_create_struct,
type_create_subarray,
type_delete_attr,
type_dup,
type_extent,
type_f2c,
type_free,
type_free_keyval,
type_get_attr,
type_get_contents,
type_get_envelope,
type_get_extent,
type_get_extent_x,
type_get_name,
type_get_true_extent,
type_get_true_extent_x,
type_hindexed,
type_hvector,
type_indexed,
type_lb,
type_match_size,
type_set_attr,
type_set_name,
type_size,
type_size_x,
type_struct,
type_ub,
type_vector,
unpack,
unpack_external,
unpublish_name,
waitall,
waitany,
wait,
waitsome,
win_allocate,
win_allocate_shared,
win_attach,
win_c2f,
win_call_errhandler,
win_complete,
win_create,
win_create_dynamic,
win_create_errhandler,
win_create_keyval,
win_delete_attr,
win_detach,
win_f2c,
win_fence,
win_flush_all,
win_flush,
win_flush_local_all,
win_flush_local,
win_free,
win_free_keyval,
win_get_attr,
win_get_errhandler,
win_get_group,
win_get_info,
win_get_name,
win_lock_all,
win_lock,
win_post,
win_set_attr,
win_set_errhandler,
win_set_info,
win_set_name,
win_shared_query,
win_start,
win_sync,
win_test,
win_unlock_all,
win_unlock,
win_wait,
wtick,
wtime
};
This diff is collapsed.
This diff is collapsed.
int read_run(const char* LOG, std::map<int, MPI_Comm>& COMM_LIST);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment