int main(int argc, char *argv[]) { int numproc, rank, len; char hostname[MPI_MAX_PROCESSOR_NAME]; PMPI_Init(&argc, &argv); PMPI_Comm_size(MPI_COMM_WORLD, &numproc); PMPI_Comm_rank(MPI_COMM_WORLD, &rank); PMPI_Get_processor_name(hostname, &len); if (rank==0) { int *freq,i,j; freq=(int *)malloc(sizeof(int)*numproc); char *temp; temp=(char*)malloc(sizeof(char)*(numproc-1)); MPI_Status *stat, *stat1; stat = (MPI_Status*)malloc(sizeof(MPI_Status)*(numproc-1)); stat1 = (MPI_Status*)malloc(sizeof(MPI_Status)*(numproc-1)); MPI_Request *req; req = (MPI_Request *)malloc(sizeof(MPI_Request)*(numproc-1)); int N=numproc*numproc; for(i=1; i<numproc; i++) { PMPI_Recv(temp+i-1, 1, MPI_CHAR, i, 0, MPI_COMM_WORLD, stat+(i-1));//, req+(i-1)*2); } for(i=1; i<numproc; i++) { PMPI_Recv(freq+i*numproc, numproc, MPI_INT, i, 1, MPI_COMM_WORLD, stat1+(i-1)); } printf("echo\n"); // MPI_Waitall((numproc-1), req, stat); for (i=1; i<numproc; i++) { printf("Rank %d ", i); for (j=0; j<numproc; j++) { if(j!=i) { int loc = i*numproc+j; printf("%d ",freq[loc]); } } printf("\n"); } } else { int i, *nsend; char *rMsg, msg='x'; rMsg=(char*)malloc(sizeof(char)); nsend=(int*)malloc(sizeof(int)*numproc); // msg=(char*)malloc(sizeof(char)); // memset(msg, 'z', sizeof(char)); memset(nsend, 0, sizeof(int)*numproc); MPI_Request *req; req = (MPI_Request *)malloc(sizeof(MPI_Request)*(numproc)); MPI_Status *stat; stat = (MPI_Status*)malloc(sizeof(MPI_Status)*(numproc-1)); for (i=0; i<numproc; i++) { if(i!=rank) { *(nsend+i)+=*(nsend+i)+1; PMPI_Isend(&msg, 1, MPI_CHAR, i, 0, MPI_COMM_WORLD, &(req[i])); } } // printf("Echo-1\n"); for (i=1; i<numproc; i++) { if (i!=rank) PMPI_Recv(rMsg, 1, MPI_CHAR, i, 0, MPI_COMM_WORLD, stat+i-1); } // printf("Echo-2\n"); MPI_Isend(nsend, numproc, MPI_INT, 0, 1, MPI_COMM_WORLD, req+numproc); // MPI_Isend(msg, 1, MPI_CHAR, i, 0, MPI_COMM_WORLD, req+numproc); // printf("Echo-3\n"); } PMPI_Finalize(); return(0); }
/* task level init - executed by each MPI task only once immediately after MPI_Init */ void mpiPi_init (char *appName) { if (time (&mpiPi.start_timeofday) == (time_t) - 1) { mpiPi_msg_warn ("Could not get time of day from time()\n"); } mpiPi.toolname = "mpiP"; mpiPi.comm = MPI_COMM_WORLD; mpiPi.tag = 9821; mpiPi.procID = getpid (); mpiPi.appName = strdup (appName); PMPI_Comm_rank (mpiPi.comm, &mpiPi.rank); PMPI_Comm_size (mpiPi.comm, &mpiPi.size); PMPI_Get_processor_name (mpiPi.hostname, &mpiPi.hostnamelen); mpiPi.stdout_ = stdout; mpiPi.stderr_ = stderr; mpiPi.lookup = mpiPi_lookup; mpiPi.enabled = 1; mpiPi.enabledCount = 1; mpiPi.cumulativeTime = 0.0; mpiPi.global_app_time = 0.0; mpiPi.global_mpi_time = 0.0; mpiPi.global_mpi_size = 0.0; mpiPi.global_mpi_io = 0.0; mpiPi.global_mpi_msize_threshold_count = 0; mpiPi.global_mpi_sent_count = 0; mpiPi.global_time_callsite_count = 0; mpiPi.global_task_info = NULL; char tmpfilename[64]; sprintf(tmpfilename,"%d.trace\0",mpiPi.rank); mpiPi.recfile = fopen(tmpfilename,"wb"); printf("Open Rec File %s !\n", tmpfilename); /* set some defaults values */ mpiPi.collectorRank = 0; mpiPi.tableSize = 256; mpiPi.stackDepth = 1; /* the value 2 includes parent wrapper function */ mpiPi.reportPrintThreshold = 0.0; mpiPi.baseNames = 0; mpiPi.reportFormat = MPIP_REPORT_SCI_FORMAT; mpiPi.calcCOV = 1; mpiPi.inAPIrtb = 0; mpiPi.do_lookup = 1; mpiPi.messageCountThreshold = -1; mpiPi.report_style = mpiPi_style_verbose; mpiPi.print_callsite_detail = 1; #ifdef COLLECTIVE_REPORT_DEFAULT mpiPi.collective_report = 1; #else mpiPi.collective_report = 0; #endif mpiPi_getenv (); mpiPi.task_callsite_stats = h_open (mpiPi.tableSize, mpiPi_callsite_stats_pc_hashkey, mpiPi_callsite_stats_pc_comparator); /* -- welcome msg only collector */ if (mpiPi.collectorRank == mpiPi.rank) { mpiPi_msg ("\n"); mpiPi_msg ("%s V%d.%d.%d (Build %s/%s)\n", mpiPi.toolname, mpiPi_vmajor, mpiPi_vminor, mpiPi_vpatch, mpiPi_vdate, mpiPi_vtime); mpiPi_msg ("Direct questions and errors to %s\n", MPIP_HELP_LIST); mpiPi_msg ("\n"); } mpiPi_msg_debug ("appName is %s\n", appName); mpiPi_msg_debug ("successful init on %d, %s\n", mpiPi.rank, mpiPi.hostname); if (mpiPi.enabled) { mpiPi_GETTIME (&mpiPi.startTime); } return; }
int MPI_Get_processor_name(char *name, int *resultlen) { return PMPI_Get_processor_name(name, resultlen); }
void mpiPi_init (char *appName) { if (time (&mpiPi.start_timeofday) == (time_t) - 1) { mpiPi_msg_warn ("Could not get time of day from time()\n"); } mpiPi.toolname = "mpiP"; mpiPi.comm = MPI_COMM_WORLD; mpiPi.tag = 9821; mpiPi.procID = getpid (); mpiPi.appName = strdup (appName); PMPI_Comm_rank (mpiPi.comm, &mpiPi.rank); PMPI_Comm_size (mpiPi.comm, &mpiPi.size); PMPI_Get_processor_name (mpiPi.hostname, &mpiPi.hostnamelen); mpiPi.stdout_ = stdout; mpiPi.stderr_ = stderr; mpiPi.lookup = mpiPi_lookup; mpiPi.enabled = 1; mpiPi.enabledCount = 1; mpiPi.cumulativeTime = 0.0; mpiPi.global_app_time = 0.0; mpiPi.global_mpi_time = 0.0; mpiPi.global_mpi_size = 0.0; mpiPi.global_mpi_io = 0.0; mpiPi.global_mpi_rma = 0.0; mpiPi.global_mpi_msize_threshold_count = 0; mpiPi.global_mpi_sent_count = 0; mpiPi.global_time_callsite_count = 0; mpiPi.global_task_hostnames = NULL; mpiPi.global_task_app_time = NULL; mpiPi.global_task_mpi_time = NULL; /* set some defaults values */ mpiPi.collectorRank = 0; mpiPi.tableSize = 256; mpiPi.reportPrintThreshold = 0.0; mpiPi.baseNames = 0; mpiPi.reportFormat = MPIP_REPORT_SCI_FORMAT; mpiPi.calcCOV = 1; mpiPi.inAPIrtb = 0; mpiPi.do_lookup = 1; mpiPi.messageCountThreshold = -1; if (DEFAULT_REPORT_FORMAT == mpiPi_style_concise) { mpiPi.report_style = mpiPi_style_concise; mpiPi.stackDepth = 0; mpiPi.print_callsite_detail = 0; } else // verbose default { mpiPi.report_style = mpiPi_style_verbose; mpiPi.stackDepth = 1; mpiPi.print_callsite_detail = 1; } #ifdef COLLECTIVE_REPORT_DEFAULT mpiPi.collective_report = 1; #else mpiPi.collective_report = 0; #endif mpiPi.disable_finalize_report = 0; mpiPi.do_collective_stats_report = 0; mpiPi.do_pt2pt_stats_report = 0; #ifdef SO_LOOKUP mpiPi.so_info = NULL; #endif mpiPi.do_pt2pt_detail_report = 0; mpiPi_getenv (); mpiPi.task_callsite_stats = h_open (mpiPi.tableSize, mpiPi_callsite_stats_pc_hashkey, mpiPi_callsite_stats_pc_comparator); mpiPi.accumulatedPt2ptCounts = NULL; mpiPi.accumulatedPt2ptData = NULL; if (mpiPi.do_collective_stats_report == 1) { init_histogram (&mpiPi.coll_comm_histogram, 7, 32, NULL); init_histogram (&mpiPi.coll_size_histogram, 7, 32, NULL); } if (mpiPi.do_pt2pt_stats_report == 1) { init_histogram (&mpiPi.pt2pt_comm_histogram, 7, 32, NULL); init_histogram (&mpiPi.pt2pt_size_histogram, 7, 32, NULL); if(mpiPi.do_pt2pt_detail_report == 1) { mpiPi.task_pt2pt_stats = h_open(mpiPi.tableSize, mpiPi_pt2pt_stats_rank_hashkey, mpiPi_pt2pt_stats_rank_comparator); } } /* -- welcome msg only collector */ if (mpiPi.collectorRank == mpiPi.rank) { mpiPi_msg (""); mpiPi_msg ("%s V%d.%d.%d (Build %s/%s)\n", mpiPi.toolname, mpiPi_vmajor, mpiPi_vminor, mpiPi_vpatch, mpiPi_vdate, mpiPi_vtime); mpiPi_msg ("Direct questions and errors to %s\n", MPIP_HELP_LIST); mpiPi_msg ("\n"); } mpiPi_msg_debug ("appName is %s\n", appName); mpiPi_msg_debug ("sizeof(callsite_stats_t) is %d\n", sizeof (callsite_stats_t)); mpiPi_msg_debug ("successful init on %d, %s\n", mpiPi.rank, mpiPi.hostname); if (mpiPi.enabled) { mpiPi_GETTIME (&mpiPi.startTime); } return; }
/* * If MPICH is built with the --enable-debugger option, MPI_Init and * MPI_Init_thread will call MPIR_WaitForDebugger. This ensures both that * the debugger can gather information on the MPI job before the MPI_Init * returns to the user and that the necessary symbols for providing * information such as message queues is available. * * In addition, the environment variable MPIEXEC_DEBUG, if set, will cause * all MPI processes to wait in this routine until the variable * MPIR_debug_gate is set to 1. */ void MPIR_WaitForDebugger( void ) { #ifdef MPIU_PROCTABLE_NEEDED int rank = MPIR_Process.comm_world->rank; #if defined(FINEGRAIN_MPI) int size = MPIR_Process.comm_world->num_osprocs; #else int size = MPIR_Process.comm_world->local_size; #endif int i, maxsize; /* FIXME: In MPICH, the executables may not have the information on the other processes; this is part of the Process Manager Interface (PMI). We need another way to provide this information to a debugger */ /* The process manager probably has all of this data - the MPI2 debugger interface API provides (at least originally) a way to access this. */ /* Also, to avoid scaling problems, we only populate the first 64 entries (default) */ maxsize = MPIR_CVAR_PROCTABLE_SIZE; if (maxsize > size) maxsize = size; if (rank == 0) { char hostname[MPI_MAX_PROCESSOR_NAME+1]; int hostlen; int val; MPIR_proctable = (MPIR_PROCDESC *)MPIU_Malloc( size * sizeof(MPIR_PROCDESC) ); for (i=0; i<size; i++) { /* Initialize the proctable */ MPIR_proctable[i].host_name = 0; MPIR_proctable[i].executable_name = 0; MPIR_proctable[i].pid = -1; } PMPI_Get_processor_name( hostname, &hostlen ); MPIR_proctable[0].host_name = (char *)MPIU_Strdup( hostname ); MPIR_proctable[0].executable_name = 0; MPIR_proctable[0].pid = getpid(); for (i=1; i<maxsize; i++) { int msg[2]; PMPI_Recv( msg, 2, MPI_INT, i, 0, MPI_COMM_WORLD,MPI_STATUS_IGNORE); MPIR_proctable[i].pid = msg[1]; MPIR_proctable[i].host_name = (char *)MPIU_Malloc( msg[0] + 1 ); PMPI_Recv( MPIR_proctable[i].host_name, msg[0]+1, MPI_CHAR, i, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE ); MPIR_proctable[i].host_name[msg[0]] = 0; } MPIR_proctable_size = size; /* Debugging hook */ if (MPIR_CVAR_PROCTABLE_PRINT) { for (i=0; i<maxsize; i++) { printf( "PT[%d].pid = %d, .host_name = %s\n", i, MPIR_proctable[i].pid, MPIR_proctable[i].host_name ); } fflush( stdout ); } MPIR_Add_finalize( MPIR_FreeProctable, MPIR_proctable, 0 ); } else { char hostname[MPI_MAX_PROCESSOR_NAME+1]; int hostlen; int mypid = getpid(); int msg[2]; if (rank < maxsize) { PMPI_Get_processor_name( hostname, &hostlen ); msg[0] = hostlen; msg[1] = mypid; /* Deliver to the root process the proctable information */ PMPI_Ssend( msg, 2, MPI_INT, 0, 0, MPI_COMM_WORLD ); PMPI_Ssend( hostname, hostlen, MPI_CHAR, 0, 0, MPI_COMM_WORLD ); } } #endif /* MPIU_PROCTABLE_NEEDED */ /* Put the breakpoint after setting up the proctable */ MPIR_debug_state = MPIR_DEBUG_SPAWNED; #ifdef MPIU_BREAKPOINT_NEEDED (void)MPIR_Breakpoint(); #endif /* After we exit the MPIR_Breakpoint routine, the debugger may have set variables such as MPIR_being_debugged */ /* Initialize the sendq support */ SendqInit(); if (getenv("MPIEXEC_DEBUG")) { while (!MPIR_debug_gate) ; } }