int ompi_common_mx_initialize(void) { mx_return_t mx_return; struct mca_mpool_base_resources_t mpool_resources; int index, value; ompi_common_mx_initialize_ref_cnt++; if(ompi_common_mx_initialize_ref_cnt == 1) { /* set the MX error handle to always return. This function is the * only MX function allowed to be called before mx_init in order * to make sure that if the MX is not up and running the MX * library does not exit the application. */ mx_set_error_handler(MX_ERRORS_RETURN); /* If we have a memory manager available, and mpi_leave_pinned == -1, then set mpi_leave_pinned to 1. We have a memory manager if: - we have both FREE and MUNMAP support - we have MUNMAP support and the linux mallopt */ value = opal_mem_hooks_support_level(); if ((value & (OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT)) == (OPAL_MEMORY_FREE_SUPPORT | OPAL_MEMORY_MUNMAP_SUPPORT)) { index = mca_base_param_find("mpi", NULL, "leave_pinned"); if (index >= 0) if ((mca_base_param_lookup_int(index, &value) == OPAL_SUCCESS) && (value == -1)) { ompi_mpi_leave_pinned = 1; setenv("MX_RCACHE", "2", 1); mpool_resources.regcache_clean = mx__regcache_clean; ompi_common_mx_fake_mpool = mca_mpool_base_module_create("fake", NULL, &mpool_resources); if (!ompi_common_mx_fake_mpool) { ompi_mpi_leave_pinned = 0; setenv("MX_RCACHE", "0", 1); opal_output(0, "Error creating fake mpool (error %s)\n", strerror(errno)); } } } /* initialize the mx library */ mx_return = mx_init(); if(MX_SUCCESS != mx_return) { opal_output(0, "Error in mx_init (error %s)\n", mx_strerror(mx_return)); return OMPI_ERR_NOT_AVAILABLE; } } return OMPI_SUCCESS; }
static int init_mx( MPIDI_PG_t *pg_p ) { mx_endpoint_addr_t local_endpoint_addr; mx_return_t ret; mx_param_t param; int mpi_errno = MPI_SUCCESS; int r; r = MPL_putenv("MX_DISABLE_SHARED=1"); MPIU_ERR_CHKANDJUMP(r, mpi_errno, MPI_ERR_OTHER, "**putenv"); r = MPL_putenv("MX_DISABLE_SELF=1"); MPIU_ERR_CHKANDJUMP(r, mpi_errno, MPI_ERR_OTHER, "**putenv"); ret = mx_init(); MPIU_ERR_CHKANDJUMP1 (ret != MX_SUCCESS, mpi_errno, MPI_ERR_OTHER, "**mx_init", "**mx_init %s", mx_strerror (ret)); mx_set_error_handler(MX_ERRORS_RETURN); /* ret = mx_get_info(NULL, MX_NIC_COUNT, NULL, 0, &nic_count, sizeof(int)); MPIU_ERR_CHKANDJUMP1 (ret != MX_SUCCESS, mpi_errno, MPI_ERR_OTHER, "**mx_get_info", "**mx_get_info %s", mx_strerror (ret)); count = ++nic_count; mx_nics = (uint64_t *)MPIU_Malloc(count*sizeof(uint64_t)); ret = mx_get_info(NULL, MX_NIC_IDS, NULL, 0, mx_nics, count*sizeof(uint64_t)); MPIU_ERR_CHKANDJUMP1 (ret != MX_SUCCESS, mpi_errno, MPI_ERR_OTHER, "**mx_get_info", "**mx_get_info %s", mx_strerror (ret)); do{ ret = mx_nic_id_to_board_number(mx_nics[index],&mx_board_num); index++; }while(ret != MX_SUCCESS); */ #ifndef USE_CTXT_AS_MARK param.key = MX_PARAM_CONTEXT_ID; param.val.context_id.bits = NEM_MX_MATCHING_BITS - SHIFT_TYPE; param.val.context_id.shift = SHIFT_TYPE; ret = mx_open_endpoint(MX_ANY_NIC,MX_ANY_ENDPOINT,MPID_NEM_MX_FILTER,¶m,1,&MPID_nem_mx_local_endpoint); #else ret = mx_open_endpoint(MX_ANY_NIC,MX_ANY_ENDPOINT,MPID_NEM_MX_FILTER,NULL,0,&MPID_nem_mx_local_endpoint); #endif MPIU_ERR_CHKANDJUMP1 (ret != MX_SUCCESS, mpi_errno, MPI_ERR_OTHER, "**mx_open_endpoint", "**mx_open_endpoint %s", mx_strerror (ret)); ret = mx_get_endpoint_addr(MPID_nem_mx_local_endpoint,&local_endpoint_addr); MPIU_ERR_CHKANDJUMP1 (ret != MX_SUCCESS, mpi_errno, MPI_ERR_OTHER, "**mx_get_endpoint_addr", "**mx_get_endpoint_addr %s", mx_strerror (ret)); ret = mx_decompose_endpoint_addr(local_endpoint_addr,&MPID_nem_mx_local_nic_id,&MPID_nem_mx_local_endpoint_id); MPIU_ERR_CHKANDJUMP1 (ret != MX_SUCCESS, mpi_errno, MPI_ERR_OTHER, "**mx_decompose_endpoint_addr", "**mx_decompose_endpoint_addr %s", mx_strerror (ret)); fn_exit: return mpi_errno; fn_fail: goto fn_exit; }
int main(int argc, char **argv) { mx_endpoint_t ep; uint64_t nic_id; uint16_t my_eid; uint64_t his_nic_id; uint32_t board_id; uint32_t filter; uint16_t his_eid; mx_endpoint_addr_t his_addr; char *rem_host; int len; int iter; int c; int do_wait; int do_bothways; extern char *optarg; mx_return_t ret; #if DEBUG extern int mx_debug_mask; mx_debug_mask = 0xFFF; #endif mx_init(); MX_MUTEX_INIT(&stream_mutex); /* set up defaults */ rem_host = NULL; filter = FILTER; my_eid = DFLT_EID; his_eid = DFLT_EID; board_id = MX_ANY_NIC; len = DFLT_LEN; iter = DFLT_ITER; do_wait = 0; do_bothways = 0; num_threads = 1; while ((c = getopt(argc, argv, "hd:e:f:n:b:r:l:N:Vvwx")) != EOF) switch(c) { case 'd': rem_host = optarg; break; case 'e': my_eid = atoi(optarg); break; case 'f': filter = atoi(optarg); break; case 'n': sscanf(optarg, "%"SCNx64, &nic_id); mx_nic_id_to_board_number(nic_id, &board_id); break; case 'b': board_id = atoi(optarg); break; case 'r': his_eid = atoi(optarg); break; case 'l': len = atoi(optarg); if (len > MAX_LEN) { fprintf(stderr, "len too large, max is %d\n", MAX_LEN); exit(1); } break; case 'N': iter = atoi(optarg); break; case 'V': Verify = 1; break; case 'v': do_verbose = 1; break; case 'w': do_wait = 1; break; case 'x': #if MX_THREAD_SAFE do_bothways = 1; #else fprintf(stderr, "bi-directional mode only supported with threadsafe mx lib\n"); exit(1); #endif break; case 'h': default: usage(); exit(1); } if (rem_host != NULL) num_threads += do_bothways; ret = mx_open_endpoint(board_id, my_eid, filter, NULL, 0, &ep); if (ret != MX_SUCCESS) { fprintf(stderr, "Failed to open endpoint %s\n", mx_strerror(ret)); exit(1); } /* If no host, we are receiver */ if (rem_host == NULL) { if (do_verbose) printf("Starting streaming receiver\n"); if (Verify) { fprintf(stderr, "-V ignored. Verify must be set by sender\n"); Verify = 0; } if (do_wait) receiver_blocking(ep, MATCH_VAL_MAIN, filter); else receiver_polling(ep, MATCH_VAL_MAIN, filter); } else { /* get address of destination */ mx_hostname_to_nic_id(rem_host, &his_nic_id); mx_connect(ep, his_nic_id, his_eid, filter, MX_INFINITE, &his_addr); if (do_verbose) printf("Starting streaming send to host %s\n", rem_host); if (Verify) printf("Verifying results\n"); /* start up the sender */ if (do_wait) sender_blocking(ep, his_addr, iter, len, do_bothways,MATCH_VAL_MAIN); else sender_polling(ep, his_addr, iter, len, do_bothways, MATCH_VAL_MAIN); } mx_close_endpoint(ep); mx_finalize(); exit(0); }
/* * main */ int main (int argc, char *argv[]) { GdkGLConfig *glConfig; GtkWidget *mainWindow; GtkWidget *copterDrawingArea; extern int optind; extern int optopt; extern int opterr; extern int optreset; char *optstr="d:m:s:h"; char *sdev = NULL; int sspeed = -1; int opt = 0; /* * Init argument control */ opt = getopt( argc, argv, optstr); while( opt != -1 ) { switch( opt ) { case 'd': sdev = optarg; break; case 'm': copter_filename = optarg; case 's': sspeed = atoi(optarg); break; case 'h': usage(); return 0; default: break; } opt = getopt(argc, argv, optstr); } if (!g_thread_supported ()) { g_thread_init (NULL); } gdk_threads_init (); gdk_threads_enter (); /* * Init GTK+ and GtkGLExt. */ gtk_init (&argc, &argv); gtk_gl_init (&argc, &argv); /* * Configure a OpenGL-capable context. */ // Try to make it double-buffered. glConfig = gdk_gl_config_new_by_mode (GDK_GL_MODE_RGB | GDK_GL_MODE_DEPTH | GDK_GL_MODE_ALPHA | GDK_GL_MODE_DOUBLE); if (glConfig == NULL) { g_print ("Cannot configure a double-buffered context.\n"); g_print ("Will try a single-buffered context.\n"); // If we can't configure a double-buffered context, try for single-buffered. glConfig = gdk_gl_config_new_by_mode (GDK_GL_MODE_RGB | GDK_GL_MODE_DEPTH | GDK_GL_MODE_ALPHA); if (glConfig == NULL) { g_critical ("Aargh! Cannot configure any type of OpenGL-capable context. Exiting.\n"); return -1; } } /* * Load the GTK interface. */ theXml = gtk_builder_new (); gtk_builder_add_from_file (theXml, "amcc.glade", NULL); if (theXml == NULL) { g_critical ("Failed to load an initialise the GTK file.\n"); return -1; } /* * Get the top-level window reference from loaded Glade file. */ mainWindow = GTK_WIDGET (gtk_builder_get_object (theXml, "windowMain")); // Set unassigned widgets to get handled automatically by the window manager. gtk_container_set_reallocate_redraws (GTK_CONTAINER (mainWindow), TRUE); /* * Get the drawing area's reference from the loaded Glade file which we are going to use for OpenGL rendering. */ copterDrawingArea = GTK_WIDGET (gtk_builder_get_object (theXml, "copter")); // Add OpenGL-capability to the drawing area. gtk_widget_set_gl_capability (copterDrawingArea, glConfig, NULL, TRUE, GDK_GL_RGBA_TYPE); // Initialise the render mutex. pthread_mutex_init (&copter_render_mutex, NULL); /* * Get the window manager to connect any assigned signals in the loaded Glade file to our coded functions. */ gtk_builder_connect_signals (theXml, NULL); /* * Init channel graph */ graph_init(&acc_graph, mainWindow, 3, 0, acc_graph_callback); graph_set_channel_name(&acc_graph, 1, "Acc_X"); graph_set_channel_color(&acc_graph, 1, "#FF0000"); graph_set_channel_name(&acc_graph, 2, "Acc_Y"); graph_set_channel_color(&acc_graph, 2, "#00FF00"); graph_set_channel_name(&acc_graph, 3, "Acc_Z"); graph_set_channel_color(&acc_graph, 3, "#0000FF"); gtk_box_pack_start (GTK_BOX(GTK_WIDGET (gtk_builder_get_object (theXml, "vbox2"))), graph_get_widget(&acc_graph), TRUE, TRUE, 0); graph_set_data(&acc_graph, 0, 3300); graph_init(&gyro_graph, mainWindow, 3, 0, gyro_graph_callback); graph_set_channel_name(&gyro_graph, 1, "Gyro_X"); graph_set_channel_color(&gyro_graph, 1, "#FF0000"); graph_set_channel_name(&gyro_graph, 2, "Gyro_Y"); graph_set_channel_color(&gyro_graph, 2, "#00FF00"); graph_set_channel_name(&gyro_graph, 3, "Gyro_Z"); graph_set_channel_color(&gyro_graph, 3, "#0000FF"); gtk_box_pack_start (GTK_BOX(GTK_WIDGET (gtk_builder_get_object (theXml, "vbox3"))), graph_get_widget(&gyro_graph), TRUE, TRUE, 0); graph_set_data(&gyro_graph, 0, 3300); mx_init(&mx, serial_tx_data, (void*)&serial); serial_init(&serial, mx_rx_data, &mx); if (!sdev) sdev = DEFAULT_SERIAL_DEV; if (sspeed == -1) sspeed = 57600; serial_open(&serial, sdev, sspeed); /* * Show main window. */ gtk_widget_show (mainWindow); // attitude init; attitude_init(&attitude); // Start the render timer. g_timeout_add (1000 / 10, render_timer_event, copterDrawingArea); g_timeout_add (1000 / 10, update_accs_graph, &acc_graph); g_timeout_add (1000 / 10, update_gyros_graph, &gyro_graph); // Run the window manager loop. gtk_main (); gdk_threads_leave (); return 0; }