void session_end(session *s) { unsigned int role_idx; unsigned int role_count = s->nrole; #ifdef __DEBUG__ DEBUG_sess_end_time = sc_time(); #endif sleep(1); for (role_idx=0; role_idx<role_count; role_idx++) { switch (s->roles[role_idx]->type) { case SESSION_ROLE_P2P: assert(s->roles[role_idx]->p2p != NULL); if (zmq_close(s->roles[role_idx]->p2p->ptr)) { perror("zmq_close"); } break; case SESSION_ROLE_GRP: if (zmq_close(s->roles[role_idx]->grp->in->ptr) != 0) { perror("zmq_close"); } if (zmq_close(s->roles[role_idx]->grp->out->ptr) != 0) { perror("zmq_close"); } free(s->roles[role_idx]->grp->in); free(s->roles[role_idx]->grp->out); break; case SESSION_ROLE_INDEXED: assert(0); // TODO handle indexed endpoint break; default: fprintf(stderr, "Unable to terminate endpoint#%u: unknown type\n", role_idx); } // Switch } for (role_idx=0; role_idx<role_count; role_idx++) { free(s->roles[role_idx]); } free(s->roles); zmq_term(s->ctx); s->r = NULL; free(s); #ifdef __DEBUG__ DEBUG_prog_end_time = sc_time(); printf("----- Statistics -----\n"); printf("Total execution time (including session init and cleanup): %f sec\n", sc_time_diff(DEBUG_prog_start_time, DEBUG_prog_end_time)); printf("Total time in session: %f sec\n", sc_time_diff(DEBUG_sess_start_time, DEBUG_sess_end_time)); printf("----------------------\n"); #endif }
int main(int argc, char *argv[]) { session *s; session_init(&argc, &argv, &s, "Pingpong_A.spr"); if (argc < 3) return EXIT_FAILURE; int M = atoi(argv[1]); int N = atoi(argv[2]); printf("M: %d, N: %d\n", M, N); role *B = s->r(s, "B"); int val[M]; size_t sz = M; long long start_time = sc_time(); int i; for (i=0; i<N; i++) { memset(val, i, M * sizeof(int)); send_int_array(val, (size_t)M, B); sz = M; recv_int_array(val, &sz, B); } long long end_time = sc_time(); printf("%s: Time elapsed: %f sec\n", s->name, sc_time_diff(start_time, end_time)); session_end(s); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { if (argc < 2) return EXIT_FAILURE; int N = atoi(argv[1]); printf("N: %d\n", N); void *ctx = zmq_init(1); void *pub = zmq_socket(ctx, ZMQ_PUB); // Output channel of 0 assert(pub); void *sub = zmq_socket(ctx, ZMQ_SUB); // Input channel of 0 assert(sub); int rc; rc = zmq_bind(sub, "tcp://*:8887"); // Waits for publishers assert(rc == 0); rc = zmq_connect(pub, "tcp://localhost:8888"); // Actively connect to subscribers assert(rc == 0); zmq_setsockopt(sub, ZMQ_SUBSCRIBE, "", 0); int *val = (int *)calloc(N, sizeof(int)); zmq_msg_t msg; long long start_time = sc_time(); // Send int *buf = (int *)calloc(N, sizeof(int)); memcpy(buf, val, N * sizeof(int)); zmq_msg_init_data(&msg, buf, N * sizeof(int), _dealloc, NULL); zmq_send(pub, &msg, 0); zmq_msg_close(&msg); // Receive zmq_msg_init(&msg); zmq_recv(sub, &msg, 0); memcpy(val, (int *)zmq_msg_data(&msg), zmq_msg_size(&msg)); zmq_msg_close(&msg); long long end_time = sc_time(); printf("%s: Time elapsed: %f sec\n", argv[0], sc_time_diff(start_time, end_time)); #ifdef __DEBUG__ int i; printf("%s [ ", argv[0]); for (i=0; i<N; ++i) { printf("%d ", val[i]); } printf("]\n"); #endif free(val); zmq_close(sub); zmq_close(pub); zmq_term(ctx); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { session *s; session_init(&argc, &argv, &s, "Protocol_R2.spr"); session_dump(s); long long barrier_start = sc_time(); barrier(s->r(s, "_Others"), "R0"); long long barrier_end = sc_time(); sc_print_version(); printf("%s: Barrier time: %f sec\n", s->name, sc_time_diff(barrier_start, barrier_end)); session_end(s); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { if (argc < 3) return EXIT_FAILURE; int M = atoi(argv[1]); int N = atoi(argv[2]); printf("M: %d, N: %d\n", M, N); void *ctx = zmq_init(1); void *b = zmq_socket(ctx, ZMQ_PAIR); zmq_connect(b, "tcp://localhost:4444"); zmq_msg_t msg; int val[M]; long long start_time = sc_time(); int i; for (i=0; i<N; i++) { int *buf = (int *)malloc(M * sizeof(int)); memset(val, i, M * sizeof(int)); memcpy(buf, val, M * sizeof(int)); zmq_msg_init_data(&msg, buf, M * sizeof(int), _dealloc, NULL); zmq_send(b, &msg, 0); zmq_msg_close(&msg); zmq_msg_init(&msg); zmq_recv(b, &msg, 0); memcpy(val, (int *)zmq_msg_data(&msg), zmq_msg_size(&msg)); zmq_msg_close(&msg); } long long end_time = sc_time(); printf("zmq_a: Time elapsed: %f sec\n", sc_time_diff(start_time, end_time)); zmq_close(b); zmq_term(ctx); return EXIT_SUCCESS; }