int main(void) { pthread_t pthread[10]; struct plat_shmem_config *shmem_config = plat_alloc(sizeof(struct plat_shmem_config)); plat_shmem_config_init(shmem_config); shmem_config->size = SHM_SIZE; plat_shmem_prototype_init(shmem_config); int tmp = plat_shmem_attach(shmem_config->mmap); if (tmp) { plat_log_msg(20073, PLAT_LOG_CAT_PLATFORM_TEST_SHMEM, PLAT_LOG_LEVEL_FATAL, "shmem_attach(%s) failed: %s", shmem_config->mmap, plat_strerror(-tmp)); plat_abort(); } #ifdef MULTIQ_SCHED fthInitMultiQ(1,NUM_PTHREADS); // Tell the scheduler code NUM_PTHREADS schedulers starting up #else fthInit(); #endif for (uint64_t i = 0; i < NUM_PTHREADS; i++) { pthread_create(&pthread[i], NULL, &pthreadRoutine, (void *) i); } for (uint64_t i = 0; i < NUM_PTHREADS; i++) { pthread_join(pthread[i], NULL); } printf("Done\n"); plat_exit(exitRV); }
/* * @brief Pthread-safe pre-initialization of SDF agent engine. * * Order of initialization (change accordingly): <br> * 1. sdf_msg_init_mpi (find out who we are in the cluster?) <br> * 2. shmem initialization <br> * 3. fthInit <br> * 4. sdf_msg_init <br> * 5. sdf_msg_startmsg <br> // FIXME: merge sdf_msg_xxx calls? * * @return status, SDF_TRUE on success */ static SDF_boolean_t agent_engine_pre_init_internal(struct sdf_agent_state *state, int argc, char *argv[]) { int numScheds; uint32_t sdf_msg_numprocs; sdf_msg_init(argc, argv); state->rank = sdf_msg_myrank(); sdf_msg_numprocs = sdf_msg_numranks(); /* * Allow number of nodes to not match MPI so that node failures * can be simulated for multi-node operation as with replication * prior to the adoption of non-MPI based messaging. */ if (!state->config.nnodes) state->config.nnodes = sdf_msg_numprocs; if (!init_agent_sm_config(&state->config.shmem, state->rank)) return SDF_FALSE; if (state->config.ffdc_disable == 0) { if (ffdc_initialize(0, BLD_VERSION, state->config.ffdc_buffer_len) == 0) { plat_log_msg(21788, LOG_CAT, PLAT_LOG_LEVEL_DEBUG, "Initialized FFDC logging " "(max buffers=%d, thread bufsize=0x%lx)", FFDC_MAX_BUFFERS, (long)state->config.ffdc_buffer_len); } else { plat_log_msg(21789, LOG_CAT, PLAT_LOG_LEVEL_WARN, "Unable to initialize FFDC logging " "(max buffers=%d, thread bufsize=0x%lx)", FFDC_MAX_BUFFERS, (long)state->config.ffdc_buffer_len); } } else { plat_log_msg(10005, LOG_CAT, PLAT_LOG_LEVEL_DEBUG, "FFDC logging disabled"); } numScheds = getProperty_Int("SDF_FTHREAD_SCHEDULERS", 1); fthInitMultiQ(1, numScheds); return SDF_TRUE; }
int main(int argc, char **argv) { int ret = 0; int shmem_attached = 0; struct plat_opts_config_fthGetTimeSpeed config; int status; int i; struct state *state; struct thread_state *thread_state; long count; memset(&config, 0, sizeof(config)); plat_shmem_config_init(&config.shmem); config.npthread = DEFAULT_NPTHREAD; config.secs = DEFAULT_LIMIT_SECS; config.multiq = DEFAULT_MULTIQ; config.mode = DEFAULT_MODE; if (plat_opts_parse_fthGetTimeSpeed(&config, argc, argv)) { ret = 2; } if (!ret) { status = plat_shmem_prototype_init(&config.shmem); if (status) { plat_log_msg(20876, LOG_CAT, PLAT_LOG_LEVEL_FATAL, "shmem init failure: %s", plat_strerror(-status)); ret = 1; } } if (!ret) { status = plat_shmem_attach(plat_shmem_config_get_path(&config.shmem)); if (status) { plat_log_msg(20877, LOG_CAT, PLAT_LOG_LEVEL_FATAL, "shmem attach failure: %s", plat_strerror(-status)); ret = 1; } else { shmem_attached = 1; } } if (!ret) { if (config.multiq) { fthInitMultiQ(1, config.npthread); } else { fthInit(); } plat_calloc_struct(&state); plat_assert_always(state); state->config = &config; state->ts = plat_calloc(config.npthread, sizeof (state->ts[0])); plat_assert_always(state->ts); for (i = 0; i < state->config->npthread; ++i) { plat_calloc_struct(&thread_state); plat_assert_always(thread_state); thread_state->state = state; thread_state->index = i; state->ts[i] = thread_state; XResume(fthSpawn(&time_main, 40960), (uint64_t)thread_state); } signal(SIGALRM, alarm_handler); signal(SIGINT, alarm_handler); alarm(state->config->secs); for (i = 0; i < state->config->npthread; ++i) { status = pthread_create(&state->ts[i]->pthread, NULL, &pthread_main, NULL); plat_assert_always(!status); } count = 0; for (i = 0; i < state->config->npthread; ++i) { status = pthread_join(state->ts[i]->pthread, NULL); plat_assert_always(!status); count += state->ts[i]->count; plat_free(state->ts[i]); } plat_free(state->ts); plat_free(state); printf("%ld\n", count/config.secs); } if (shmem_attached) { status = plat_shmem_detach(); if (status) { plat_log_msg(20880, LOG_CAT, PLAT_LOG_LEVEL_FATAL, "shmem detach failure: %s", plat_strerror(-status)); ret = 1; } } plat_shmem_config_destroy(&config.shmem); return (ret); }