Пример #1
0
int main(int   argc,
         char *argv[])
{
    aligned_t tmp, ret = 0;
    int       retval;
    long      foobar   = 1234567890;
    qthread_f funcs[2] = { returner, NULL };

    CHECK_VERBOSE();

    retval = spr_init(SPR_SPMD, funcs);
    if (retval != SPR_OK) {
        fprintf(stderr, "(%03d) spr_init returned %d\n", 0, retval);
        return -1;
    }

    my_id      = spr_locale_id();
    world_size = spr_num_locales();

    iprintf("(%03d) Rank %d of %d is alive\n", my_id, my_id, world_size);

    spr_unify();

    if (my_id != 0) {
        return -2;
    }

    int target = (world_size > 1) ? 1 : 0;
    retval = qthread_fork_remote(returner, &foobar, &ret, target, sizeof(long));
    if (retval != 0) {
        fprintf(stderr, "(%03d) fork_remote returned %d\n", my_id, retval);
        return -3;
    }

    retval = qthread_readFE(&tmp, &ret);
    iprintf("(%03d) returner returned %ld\n", my_id, (long)tmp);
    if (retval != 0) {
        fprintf(stderr, "(%03d) readFE returned %d (%d)\n", my_id, retval, (int)tmp);
        return -4;
    }

    spr_fini();

    return (tmp == foobar) ? 0 : 5;
}
Пример #2
0
void main()
{
	byte i,d;
	byte *ptr;
	byte *src;
	byte tile;
	int map_xx, map_yy;

	vdp_set_mode(vdp_grp2);
	vdp_set_color(vdp_white, vdp_black);
	vdp_clear_grp1(0);
	spr_init(1,0);
	sys_irq_init();
	wq_start();

	INIT_TILE_SET(kv, tiles2);
	// need an offset of one
	tile_set_to_vram(&kv, 1);

	// show room 10
	map_xx =0; map_yy = 11;
	map_inflate_screen(map_cmpr_dict, map, fb, map_w, map_xx, map_yy);
	vdp_fastcopy_nametable(fb);

	SPR_DEFINE_PATTERN_SET(monk_patt, SPR_SIZE_16x32, 1, 2, 3, monk1);
	SPR_DEFINE_PATTERN_SET(templar_patt, SPR_SIZE_16x32, 1, 2, 2, templar);

	SPR_DEFINE_SPRITE(monk, &monk_patt, 10, monk1_color);
	SPR_DEFINE_SPRITE(templar_spr, &templar_patt, 10, templar_color);

	spr_valloc_pattern_set(&monk_patt);
	spr_valloc_pattern_set(&templar_patt);

	x = 100; y = 100;
	spr_set_pos(&monk, x, y);
	spr_show(&monk);
	spr_set_pos(&templar_spr, 10, 100);
	spr_show(&templar_spr);

	INIT_WORK(physics, monk_physics_work);
	INIT_WORK(animate, monk_animate_work);

	monk_state.jump  = 0;
	monk_state.jump_cnt = 0;

	do {
		d = sys_get_stick(0);
		if (d == 1 || d == 2 || d == 8 ) {
			if (!monk_state.jump) {
				tile = tile_on_screen_coords(x, y + 32);
				if (monk_state.collision & COLLISION_DOWN_MASK) {
					monk_state.jump = 1;
				}
			}
		}
		if (d == 3) {
			monk_state.right = 1;
		}	
		if (d == 7) {
			monk_state.left = 1; 
		}
		if (!monk_state.jump && !physics.pending)
				queue_delayed_work(&physics,0, 100);

		if (!animate.pending)
			queue_work(&animate);

		if (x > 240) {
			x = 0;
			spr_set_pos(&monk, x, y);
			vdp_screen_disable();
			map_xx += 32; map_yy = 11;
			map_inflate_screen(map_cmpr_dict, map, fb, map_w, map_xx, map_yy);
			vdp_fastcopy_nametable(fb);
			vdp_screen_enable();
		}

		// debug collisions
		/*vdp_fastcopy_nametable(fb);
		vdp_poke(vdp_base_names_grp1 + (x + 5)/ 8 + (y + 7)/ 8 * 32, 20);
		vdp_poke(vdp_base_names_grp1 + (x + 10)/ 8 + (y + 7)/ 8 * 32, 20);
		vdp_poke(vdp_base_names_grp1 + (x - 1)/ 8 + (y + 10)/ 8 * 32, 20);
		vdp_poke(vdp_base_names_grp1 + (x +18)/ 8 + (y + 10)/ 8 * 32, 20);
		vdp_poke(vdp_base_names_grp1 + (x - 1)/ 8 + (y + 28)/ 8 * 32, 20);
		vdp_poke(vdp_base_names_grp1 + (x +18)/ 8 + (y + 28)/ 8 * 32, 20);
		vdp_poke(vdp_base_names_grp1 + (x + 5)/ 8 + (y + 34)/ 8 * 32, 20);
		vdp_poke(vdp_base_names_grp1 + (x + 10)/8 + (y + 34)/ 8 * 32, 20);*/

	} while (1);
}
Пример #3
0
int main(int   argc,
         char *argv[])
{
    size_t        num_edges;
    aligned_t   * rets;
    vertex_t    * edges;

    for (int i = 0; i < NUM_VERTICES; i++) {
        in_degrees[i] = 0;
    }

    /* Initialize SPR in SPMD mode */
    qthread_f actions[2] = {incr_in_degree, NULL};
    spr_init(SPR_SPMD, actions);
    here        = spr_locale_id();
    num_locales = spr_num_locales();
    if (0 == here) {
        printf("Running with %d locales\n", num_locales);
    }

    rng_init(rng_state.state, time(NULL) * here);

    /* Create local portion of the graph */
    indices[0] = 0;
    for (int i = 1; i < NUM_VERTICES + 1; i++) {
        indices[i]    = indices[i-1] + random_vertex();
    }
    for (int i = 0; i < NUM_VERTICES + 1; i++) {
        printf("[%03d] indices[%d]: %lu\n", here, i, indices[i]);
    }

    num_edges = indices[NUM_VERTICES];
    edges = malloc(num_edges * sizeof(vertex_t));
    for (int i = 0; i < num_edges; i++) {
        edges[i].lid = random_locale();
        edges[i].vid = random_vertex();
    }
    for (int i = 0; i < num_edges; i++) {
        printf("[%03d] edges[%d]: (%lu,%lu)\n", here, i, 
               edges[i].lid, edges[i].vid);
    }

    /* TODO: barrier */

    /* Fill in-degrees property map */
    rets = malloc(num_edges * sizeof(aligned_t));
    for (int i = 0; i < NUM_VERTICES; i++) {
        for (int j = indices[i]; j < indices[i+1]; j++) {
            printf("[%03d] spawning incr of edge[%d] = (%lu,%lu)\n",
                   here, j, edges[j].lid, edges[j].vid);
            qthread_fork_remote(incr_in_degree,         /* action */
                                &(edges[j].vid),        /* local vertex id */
                                &rets[j],               /* feb */
                                edges[j].lid,           /* locale */
                                sizeof(vertex_id_t));
        }
    }
    for (int i = 0; i < num_edges; i++) {
        qthread_readFF(&rets[i], &rets[i]);
    }

    /* Print in-degrees */
    for (int i = 0; i < NUM_VERTICES; i++) {
        printf("[%03d] in-degree(%lu) = %lu\n",
               here, i, in_degrees[i]);
    }

    /* Free up allocated resources */
    free(rets);
    free(edges);

    return 0;
}
Пример #4
0
//
// initializes the communications package
//   set chpl_localeID and chpl_numLocales
// notes:
//   * Called with the argc/argv pair passed to main()
//
void chpl_comm_init(int *argc_p, char ***argv_p)
{
    qthread_debug(CHAPEL_CALLS, "[%d] begin\n", chpl_localeID);

    // Set stack size >= 8 pages (lower bound derived from experience)
    unsigned long const default_stack_size = 32768;
    unsigned long const stack_size = 
        qt_internal_get_env_num("STACK_SIZE",
                                default_stack_size,
                                default_stack_size);
    char stack_size_str[100] = {0};
    if (default_stack_size > stack_size) {
        snprintf(stack_size_str, 99, "%lu", default_stack_size);
    } else {
        snprintf(stack_size_str, 99, "%lu", stack_size);
    }
    setenv("QT_STACK_SIZE", stack_size_str, 1);

    /* Initialize SPR:                              *
     * - All locales participate in initialization. */
    int const rc = spr_init(SPR_SPMD, chapel_remote_functions);
    assert(SPR_OK == rc);

    /* Record locale info */
    chpl_localeID = spr_locale_id();
    chpl_numLocales = spr_num_locales();

    qthread_debug(CHAPEL_BEHAVIOR, "[%d] initialized SPR with %d locales\n", chpl_localeID, chpl_numLocales);

    /* Set up segment information table */
#undef malloc
    seginfo_table = malloc(chpl_numLocales * sizeof(seginfo_t));
#define malloc dont_use_malloc_use_chpl_mem_allocMany_instead

    if (0 == chpl_localeID) {
        int i;

        int global_table_size = chpl_numGlobalsOnHeap * sizeof(void *) + getpagesize();
#undef malloc
        void * global_table = malloc(global_table_size);
#define malloc dont_use_malloc_use_chpl_mem_allocMany_instead
       
        // Make sure segment is page-aligned.
        seginfo_table[0].addr = ((void *)(((uint8_t *)global_table) +
                                 (((((uintptr_t)global_table) % getpagesize()) == 0) ? 0 :
                                  (getpagesize() - (((uintptr_t)global_table) % getpagesize())))));
        seginfo_table[0].size = global_table_size;

        for (i = 1; i < chpl_numLocales; i++) {
            seginfo_table[i].addr = NULL;
            seginfo_table[i].size = 0;
        }
    }

    chpl_comm_barrier("waiting for seginfo table setup at root");

    // Broadcast segment info
    if (0 == chpl_localeID) {
        int i;
        aligned_t rets[chpl_numLocales];
        for (i = 1; i < chpl_numLocales; i++) {
            qthread_fork_remote(bcast_seginfo, seginfo_table, &rets[i], i,
                                chpl_numLocales * sizeof(seginfo_t));
        }
        for (i = 1; i < chpl_numLocales; i++) {
            qthread_readFF(&rets[i], &rets[i]);
        }
    }

    chpl_comm_barrier("waiting for seginfo table bcast");

    qthread_debug(CHAPEL_CALLS, "[%d] end\n", chpl_localeID);
}