コード例 #1
0
ファイル: sdes_note.cpp プロジェクト: asyr625/mini_sip
Sdes_Note::Sdes_Note(void *buildfrom, int max_length)
    : Sdes_Item(SDES_ITEM_NOTE)
{
    unsigned char *lengthptr = (unsigned char *)buildfrom;
    lengthptr++;
    length=*lengthptr;

    char *cptr = (char *)buildfrom;
    my_assert(*cptr == SDES_ITEM_NOTE);

    note="";

    cptr += 2;
    for (int i = 0; i < *lengthptr; i++)
    {
        note += *cptr;
        cptr ++;
    }
#ifdef DEBUG_OUTPUT
    std::cerr << "In SDES_NOTE: Parsed string name to <"<< note << ">"<< std::endl;
#endif
}
コード例 #2
0
 // C++-like allocator interface
 T* allocate() {
     unsigned long allocated_item_coded = next_free.load();
     
     int allocated_item;
     //tprintf(tinfra::err, "T[%i]: allocate first try with allocated_item %i\n", get_thread_string(), idx_decode(allocated_item_coded));
     while( true ) {
         allocated_item = idx_decode(allocated_item_coded);
         if( allocated_item == -1 ) {
             throw std::bad_alloc();
         }
         const int new_next_free = item_next_free_idx(allocated_item);
             // so here is the race
             //  1  (allocated_item AI, new_next_free NNF) pair is "read"
             //  2. (tries to commit, but ... in meantime)
             //  3.   (other thread allocates AI as a race)
             //  3.1  (NNF is allocates by other thread) ...
             //  4.   (other thread deallocates AI and it appears again as NF but now points to NNF2) 
             //  5. (commit succedds with NNF because AI is same as in 1) 
             //     BUG, NF points at NNF, which is not necessarily allocated
             //     should point at NNF2 (!?) impossible
             //     or TXN this kind of race should be detected and whole TXN shall be retried
         assert(new_next_free != allocated_item);
         //if(rand() % 2 ) my_nanosleep(1);
         const unsigned long new_next_free_coded = idx_encode(new_next_free);
         const bool change_succeded = next_free.compare_exchange_strong(allocated_item_coded, new_next_free_coded);
         if( !change_succeded ) {
             allocated_item = idx_decode(allocated_item_coded);
             //tprintf(tinfra::err, "T[%i]: allocate, retrying with allocated_item %i\n", get_thread_string(), allocated_item);
             continue;
         } else {
             //tprintf(tinfra::err, "T[%i]: allocated %i, next_free = %i\n", get_thread_string(), allocated_item, new_next_free);
         }
         break;
     }
     my_assert(_check_allocated(allocated_item));
     ++n_allocated;
     return item_ptr(allocated_item);
 }
コード例 #3
0
int32_t UnpackCmdReq(EdpPacket* pkg, int8_t** cmdid, uint16_t* cmdid_len,
                     int8_t** req, uint32_t* req_len)
{
    uint32 remainlen;
    int32_t rc;
    if (ReadRemainlen(pkg, &remainlen))
        return ERR_UNPACK_CMDREQ;

    rc = ReadUint16(pkg, cmdid_len);
    if (rc)
        return rc;
    if (ReadBytes(pkg, (uint8_t**)cmdid, *cmdid_len))
        return ERR_UNPACK_CMDREQ;

    rc = ReadUint32(pkg, req_len);
    if (rc)
        return rc;
    if (ReadBytes(pkg, (uint8_t**)req, *req_len))
        return ERR_UNPACK_CMDREQ;

    my_assert(pkg->_read_pos == pkg->_write_pos);
    return 0;
}
コード例 #4
0
ファイル: cq_mysql_cmd.c プロジェクト: powersaven/checkQ
int mysql_alter_drop_table(eng_ctx_t* eng_ctx) {    
    int ret = 0;
    MYSQL* mysql = get_server_mysql(eng_ctx->write_server);

    int             ndata   = 0;
    table_t        *ptable  = eng_ctx->table;
    table_schema_t *pschema = get_table_schema(ptable);

    const table_data_t **table_datas = get_table_val_types(ptable, &ndata);
    if (ndata <= 0)
        return 0;
    
    ret = mysql_select_db(mysql, database); 
    if (ret != 0) {
        return ret;
    }

    char *data_name = get_table_data_name(table_datas[ndata - 1]);
    if (strncmp(data_name, "col", 3) != 0) {
        return 0;
    }

    sql_gen(eng_ctx, ALTER_DROP);   
    my_assert(eng_ctx->sql);

    const char* sql = eng_ctx->sql;
    ret = mysql_real_query(mysql, sql, strlen(sql));

    if (0 == ret) {
        drop_table_data(pschema);
 
        return 0;
    } else {
        log_error("%s", mysql_error(mysql));
        return ret;
    }
}
コード例 #5
0
ファイル: ray_trace.c プロジェクト: bosstweed11/school
int main(int argc, char **argv)
{
	glutInit(&argc, argv);
	// depth buffer not really needed, but whatever
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
	glutInitWindowPosition(100, 100);
	glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);

	glutCreateWindow("Ray Tracer");
	
	
	my_assert(argc >1, "need to supply a spec file");
	read_spec(argv[1]);
	
	initGL();

	glutDisplayFunc(displayScene);
	glutReshapeFunc(resizeWindow);
	glutIdleFunc(idle);

	glutMainLoop();

	return 0;
}
コード例 #6
0
ファイル: basefun.c プロジェクト: zzy-cv/graphics_plat
// skip blank
int str_skip_blank(unsigned char *buf)
{
    unsigned char *s = buf;
    unsigned char *e = buf;
    unsigned int cur_char = 0;

    my_assert(buf);
    cur_char = *e;
    while(cur_char)
    {
        if(cur_char == ' ')
        {
            e++;
        }
        else
        {
            *s++ = *e++;
        }
        cur_char = *e;
    }
    *s = 0;

    return 0;
}
コード例 #7
0
ファイル: cq_mysql_cmd.c プロジェクト: powersaven/checkQ
int mysql_create_table(eng_ctx_t* eng_ctx) {
    int ret = 0;

    MYSQL* mysql = get_server_mysql(eng_ctx->write_server);
  
    ret = mysql_select_db(mysql, database); 
    if (ret != 0) {
        return ret;
    }

    sql_gen(eng_ctx, CREATE);   

    my_assert(eng_ctx->sql);

    const char* sql = eng_ctx->sql;
    ret = mysql_real_query(mysql, sql, strlen(sql));

    if (0 == ret) {
        return 0;
    } else {
        log_error("%s", mysql_error(mysql)); 
        return ret;
    }
}
コード例 #8
0
ファイル: glmain.c プロジェクト: Choino/school
/* assuming the spec is going to be properly written
 not error-checking here */
void read_spec(char *fname) {
	char buffer[300];
	FILE *fp;
	
	fp = fopen(fname, "r");
	my_assert(fp, "can't open spec");
	while(!feof(fp)){
		fgets(buffer, 300, fp);
		//printf("read line: %s\n", buffer);
		switch (buffer[0]) {
			case '#':
				break;
			case '0': // house
			case '1': //cube
			case '2': // sphere	
			case '3': // cone
			case '4': // torus
				//read in the shape
			{
				printf("parse object");
				parse_obj(buffer);
			}	break;
				//etc
			case 'l':
				parse_light(buffer);
				break;
				
			case 'c':
				parse_camera(buffer);
				break;
				
			default:
				break;
		}
	}
}
コード例 #9
0
ファイル: color_matrix.c プロジェクト: hjanime/PIntron
plist factors_list_create(plist ests_factorizations) {

    my_assert(ests_factorizations!=NULL);

    DEBUG("Creazione della lista dei fattori unici");


    pEST p;
    plistit plist_it_id, plist_it_f;
    pfactorization pfact;
    pfactor pf;
    plistit plist_it_factor;

    plist list_of_factors=list_create();
    plist_it_id=list_first(ests_factorizations);

    while(listit_has_next(plist_it_id)) {
        p= listit_next(plist_it_id);
        plist_it_f=list_first(p->factorizations);

        while(listit_has_next(plist_it_f)) {
            pfact=listit_next(plist_it_f);
            plist_it_factor=list_first(pfact);

            while(listit_has_next(plist_it_factor)) {
                pf=listit_next(plist_it_factor);
                if(!verify_factor(list_of_factors,pf))list_add_to_tail(list_of_factors,pf);
            }
            listit_destroy(plist_it_factor);
        }
        listit_destroy(plist_it_f);
    }
    listit_destroy(plist_it_id);

    return list_of_factors;
}
コード例 #10
0
ファイル: wi_winma.c プロジェクト: j13s/devil
void wi_undrawwin(struct wi_window *wi) {
    if (!wi->drawn) {
        return;
    }

    my_assert(wi != NULL && wi->bg != NULL);

    if (wi->w.refresh != wr_routine) {
        if (wi->in) {
            ws_freebitmap(wi->in);
            wi->in = NULL;
        }

        checkmem( wi->in = ws_savebitmap( NULL, w_xwinincoord(&wi->w, 0),
                                         w_ywinincoord(&wi->w,
                                                       0),
                                         w_xwininsize(&wi->w),
                                         w_ywininsize(&wi->w) ) );
    }

    ws_restorebitmap(wi->bg);
    wi->bg = NULL;
    wi->drawn = 0;
}
コード例 #11
0
ファイル: tests.c プロジェクト: GLAVAK/NSU-15203-Labs
void run_tests(void)
{
	Tree_node * tree = tree_create(42);
	Tree_node * node = tree_insert_balanced(tree, 50);
	my_assert(tree_find(tree, 50) == node);
	
	Tree_node * node2 = tree_insert_balanced(tree, 30);
	my_assert(tree_get_height(tree) == 2);
	
	tree_insert_raw(node2, 5, LEFT);
	my_assert(tree->left->left->data == 5);
	
	tree_insert_balanced(tree, 30);
	my_assert(tree->left->left->data == 5);

	tree_delete_node(tree, LEFT);
	my_assert(tree->left == NULL);
	my_assert(tree_get_height(tree) == 2);

	my_assert_conclude();
}
コード例 #12
0
int32_t WriteUint16(Buffer* buf, uint16_t val)
{
    my_assert(buf->_read_pos == 0);
    return WriteByte(buf, MOSQ_MSB(val))
           || WriteByte(buf, MOSQ_LSB(val));
}
コード例 #13
0
ファイル: tile.c プロジェクト: liljencrantz/anna-game
heightmap_element_t *tile_hid_lookup(tile_t *tile, hid_t hid)
{
    if(HID_GET_LEVEL(hid) < TILE_LEVELS)
    {
/*
	printf(
	    "Direct tile hid lookup. %d, %d\n\n",
	    HID_GET_LEVEL(hid), HID_GET_IDX(hid));
*/
	return &tile->hm[TILE_HM_OFFSET(HID_GET_LEVEL(hid)) + HID_GET_IDX(hid)];
    }
    else
    {
	hid_t hid2;

	unsigned int x_pos = HID_GET_X_POS(hid);
	unsigned int y_pos = HID_GET_Y_POS(hid);
	
	HID_SET_LEVEL(hid2,HID_GET_LEVEL(hid)-TILE_LEVELS);
	
	unsigned int len = TILE_SUBTILE_HM_PER_TILE(HID_GET_LEVEL(hid2));

	unsigned int subtile_x_pos = x_pos % len;
	unsigned int subtile_x_idx = x_pos / len;
	
	unsigned int subtile_y_pos = y_pos % len;
	unsigned int subtile_y_idx = y_pos / len;

	HID_SET_POS(hid2, subtile_x_pos, subtile_y_pos);
	
	unsigned int subtile_idx = subtile_x_idx + subtile_y_idx*TILE_SUBTILE_COUNT_PER_SIDE;
//	printf("x %d, y %d => %d, %d\n", x_pos, y_pos, subtile_x_idx, subtile_y_idx);
/*
	if(
	    (subtile_x_pos == 0 && subtile_x_idx==TILE_SUBTILE_COUNT_PER_SIDE) ||
	    (subtile_y_pos == 0 && subtile_y_idx==TILE_SUBTILE_COUNT_PER_SIDE))
	{
	    return &tile_default_he;	    
	}
*/	
	
	my_assert(subtile_x_idx < TILE_SUBTILE_COUNT_PER_SIDE);
	my_assert(subtile_y_idx < TILE_SUBTILE_COUNT_PER_SIDE);

/*	
	printf(
	    "Subtile lookup. %d, %d => %d, (%d,%d) => %d, %d, (%d,%d) => %d, %d, %d\n",
	    HID_GET_LEVEL(hid), HID_GET_IDX(hid),
	    HID_GET_LEVEL(hid), x_pos, y_pos,
	    subtile_idx, HID_GET_LEVEL(hid2), subtile_x_pos, subtile_y_pos,
	    subtile_idx, HID_GET_LEVEL(hid2), HID_GET_IDX(hid2));
*/
	if(!tile->subtile[subtile_idx])
	{
/*	    printf(
		"Null hm lookup. %d, %d\n",
		HID_GET_LEVEL(hid), HID_GET_IDX(hid));
*/
	    return 0;
	    return &tile_default_he;
	}
//	printf("subtile %d at %d\n", subtile_idx, tile->subtile[subtile_idx]);
	return tile_hid_lookup(
	    tile->subtile[subtile_idx],
	    hid2);
    }
}
コード例 #14
0
ファイル: mkdef_ord.c プロジェクト: nihilus/ia32rtools
int main(int argc, char *argv[])
{
  const struct parsed_proto *pp;
  FILE *fout, *fhdr;
  char basename[256] = { 0, };
  char line[256];
  char fmt[256];
  char word[256];
  int noname = 0;
  const char *p2;
  char *p;
  int arg;
  int ret, ord;
  int l;

  for (arg = 1; arg < argc; arg++) {
    if (IS(argv[arg], "-n"))
      noname = 1;
    else if (IS(argv[arg], "-b") && arg < argc - 1)
      snprintf(basename, sizeof(basename), "%s", argv[++arg]);
    else
      break;
  }

  if (argc != arg + 2) {
    printf("usage:\n%s [-n] [-b <basename>] <.h> <.def>\n", argv[0]);
    return 1;
  }

  hdrfn = argv[arg++];
  fhdr = fopen(hdrfn, "r");
  my_assert_not(fhdr, NULL);

  fout = fopen(argv[arg++], "w");
  my_assert_not(fout, NULL);

  if (basename[0] == 0) {
    p = strrchr(hdrfn, '.');
    my_assert_not(p, NULL);
    p2 = strrchr(hdrfn, '/');
    if (p2++ == NULL)
      p2 = hdrfn;
    l = p - p2;
    my_assert((unsigned int)l < 256, 1);
    memcpy(basename, p2, l);
    basename[l] = 0;
  }

  snprintf(fmt, sizeof(fmt), "%s_%%d", basename);

  fprintf(fout, "LIBRARY %s\n", basename);
  fprintf(fout, "EXPORTS\n");

  while (fgets(line, sizeof(line), fhdr))
  {
    p = sskip(line);
    if (*p == 0)
      continue;

    if (IS_START(p, "//"))
      continue;

    ret = 0;
    while (p != NULL && *p != 0) {
      p = next_word(word, sizeof(word), p);
      ret = sscanf(word, fmt, &ord);
      if (ret == 1)
        break;
    }
    if (ret != 1) {
      printf("scan for '%s' failed for '%s'\n", fmt, line);
      return 1;
    }

    snprintf(word, sizeof(word), fmt, ord);
    pp = proto_parse(fhdr, word, 0);
    if (pp == NULL)
      return 1;

    fputc(' ', fout);
    fputc(pp->is_fastcall ? '@' : ' ', fout);
    fprintf(fout, "%s", word);
    if (pp->is_stdcall)
      fprintf(fout, "@%-2d", pp->argc * 4);
    else
      fprintf(fout, "   ");
    fprintf(fout, " @%d", ord);
    if (noname)
      fprintf(fout, " NONAME");
    fprintf(fout, "\n");
  }

  fclose(fhdr);
  fclose(fout);
  return 0;
}
コード例 #15
0
ファイル: nonblocking3.c プロジェクト: R7R8/simgrid
static void check_after_completion(struct laundry *l)
{
    int i, j;
    int rank, size;
    MPI_Comm comm   = l->comm;
    int *buf        = l->buf;
    int *recvbuf    = l->recvbuf;
    int *sendcounts = l->sendcounts;
    int *recvcounts = l->recvcounts;
    int *sdispls    = l->sdispls;
    int *rdispls    = l->rdispls;
    int *sendtypes  = l->sendtypes;
    int *recvtypes  = l->recvtypes;
    char *buf_alias = (char *)buf;

    MPI_Comm_rank(comm, &rank);
    MPI_Comm_size(comm, &size);

    /* these cases all correspond to cases in start_random_nonblocking */
    switch (l->case_num) {
        case 0: /* MPI_Ibcast */
            for (i = 0; i < COUNT; ++i) {
                if (buf[i] != i)
                    printf("buf[%d]=%d i=%d\n", i, buf[i], i);
                my_assert(buf[i] == i);
            }
            break;

        case 1: /* MPI_Ibcast (again, but designed to stress scatter/allgather impls) */
            for (i = 0; i < PRIME; ++i) {
                if (buf_alias[i] != i)
                    printf("buf_alias[%d]=%d i=%d\n", i, buf_alias[i], i);
                my_assert(buf_alias[i] == i);
            }
            break;

        case 2: /* MPI_Ibarrier */
            /* nothing to check */
            break;

        case 3: /* MPI_Ireduce */
            if (rank == 0) {
                for (i = 0; i < COUNT; ++i) {
                    if (recvbuf[i] != ((size * (size-1) / 2) + (i * size)))
                        printf("got recvbuf[%d]=%d, expected %d\n", i, recvbuf[i], ((size * (size-1) / 2) + (i * size)));
                    my_assert(recvbuf[i] == ((size * (size-1) / 2) + (i * size)));
                }
            }
            break;

        case 4: /* same again, use a user op and free it before the wait */
            if (rank == 0) {
                for (i = 0; i < COUNT; ++i) {
                    if (recvbuf[i] != ((size * (size-1) / 2) + (i * size)))
                        printf("got recvbuf[%d]=%d, expected %d\n", i, recvbuf[i], ((size * (size-1) / 2) + (i * size)));
                    my_assert(recvbuf[i] == ((size * (size-1) / 2) + (i * size)));
                }
            }
            break;

        case 5: /* MPI_Iallreduce */
            for (i = 0; i < COUNT; ++i) {
                if (recvbuf[i] != ((size * (size-1) / 2) + (i * size)))
                    printf("got recvbuf[%d]=%d, expected %d\n", i, recvbuf[i], ((size * (size-1) / 2) + (i * size)));
                my_assert(recvbuf[i] == ((size * (size-1) / 2) + (i * size)));
            }
            break;

        case 6: /* MPI_Ialltoallv (a weak test, neither irregular nor sparse) */
            for (i = 0; i < size; ++i) {
                for (j = 0; j < COUNT; ++j) {
                    /*printf("recvbuf[%d*COUNT+%d]=%d, expecting %d\n", i, j, recvbuf[i*COUNT+j], (i + (rank * j)));*/
                    my_assert(recvbuf[i*COUNT+j] == (i + (rank * j)));
                }
            }
            break;

        case 7: /* MPI_Igather */
            if (rank == 0) {
                for (i = 0; i < size; ++i) {
                    for (j = 0; j < COUNT; ++j) {
                        my_assert(recvbuf[i*COUNT+j] == i + j);
                    }
                }
            }
            else {
                for (i = 0; i < size*COUNT; ++i) {
                    my_assert(recvbuf[i] == 0xdeadbeef);
                }
            }
            break;

        case 8: /* same test again, just use a dup'ed datatype and free it before the wait */
            if (rank == 0) {
                for (i = 0; i < size; ++i) {
                    for (j = 0; j < COUNT; ++j) {
                        my_assert(recvbuf[i*COUNT+j] == i + j);
                    }
                }
            }
            else {
                for (i = 0; i < size*COUNT; ++i) {
                    my_assert(recvbuf[i] == 0xdeadbeef);
                }
            }
            break;

        case 9: /* MPI_Iscatter */
            for (j = 0; j < COUNT; ++j) {
                my_assert(recvbuf[j] == rank + j);
            }
            if (rank != 0) {
                for (i = 0; i < size*COUNT; ++i) {
                    /* check we didn't corrupt the sendbuf somehow */
                    my_assert(buf[i] == 0xdeadbeef);
                }
            }
            break;

        case 10: /* MPI_Iscatterv */
            for (j = 0; j < COUNT; ++j) {
                my_assert(recvbuf[j] == rank + j);
            }
            if (rank != 0) {
                for (i = 0; i < size*COUNT; ++i) {
                    /* check we didn't corrupt the sendbuf somehow */
                    my_assert(buf[i] == 0xdeadbeef);
                }
            }
            for (i = 1; i < size; ++i) {
                for (j = 0; j < COUNT; ++j) {
                    /* check we didn't corrupt the rest of the recvbuf */
                    my_assert(recvbuf[i*COUNT+j] == 0xdeadbeef);
                }
            }
            break;

        case 11: /* MPI_Ireduce_scatter */
            for (j = 0; j < COUNT; ++j) {
                my_assert(recvbuf[j] == (size * rank + ((size - 1) * size) / 2));
            }
            for (i = 1; i < size; ++i) {
                for (j = 0; j < COUNT; ++j) {
                    /* check we didn't corrupt the rest of the recvbuf */
                    my_assert(recvbuf[i*COUNT+j] == 0xdeadbeef);
                }
            }
            break;

        case 12: /* MPI_Ireduce_scatter_block */
            for (j = 0; j < COUNT; ++j) {
                my_assert(recvbuf[j] == (size * rank + ((size - 1) * size) / 2));
            }
            for (i = 1; i < size; ++i) {
                for (j = 0; j < COUNT; ++j) {
                    /* check we didn't corrupt the rest of the recvbuf */
                    my_assert(recvbuf[i*COUNT+j] == 0xdeadbeef);
                }
            }
            break;

        case 13: /* MPI_Igatherv */
            if (rank == 0) {
                for (i = 0; i < size; ++i) {
                    for (j = 0; j < COUNT; ++j) {
                        my_assert(recvbuf[i*COUNT+j] == i + j);
                    }
                }
            }
            else {
                for (i = 0; i < size*COUNT; ++i) {
                    my_assert(recvbuf[i] == 0xdeadbeef);
                }
            }
            break;

        case 14: /* MPI_Ialltoall */
            for (i = 0; i < size; ++i) {
                for (j = 0; j < COUNT; ++j) {
                    /*printf("recvbuf[%d*COUNT+%d]=%d, expecting %d\n", i, j, recvbuf[i*COUNT+j], (i + (i * j)));*/
                    my_assert(recvbuf[i*COUNT+j] == (i + (rank * j)));
                }
            }
            break;

        case 15: /* MPI_Iallgather */
            for (i = 0; i < size; ++i) {
                for (j = 0; j < COUNT; ++j) {
                    my_assert(recvbuf[i*COUNT+j] == i + j);
                }
            }
            break;

        case 16: /* MPI_Iallgatherv */
            for (i = 0; i < size; ++i) {
                for (j = 0; j < COUNT; ++j) {
                    my_assert(recvbuf[i*COUNT+j] == i + j);
                }
            }
            break;

        case 17: /* MPI_Iscan */
            for (i = 0; i < COUNT; ++i) {
                my_assert(recvbuf[i] == ((rank * (rank+1) / 2) + (i * (rank + 1))));
            }
            break;

        case 18: /* MPI_Iexscan */
            for (i = 0; i < COUNT; ++i) {
                if (rank == 0)
                    my_assert(recvbuf[i] == 0xdeadbeef);
                else
                    my_assert(recvbuf[i] == ((rank * (rank+1) / 2) + (i * (rank + 1)) - (rank + i)));
            }
            break;

        case 19: /* MPI_Ialltoallw (a weak test, neither irregular nor sparse) */
            for (i = 0; i < size; ++i) {
                for (j = 0; j < COUNT; ++j) {
                    /*printf("recvbuf[%d*COUNT+%d]=%d, expecting %d\n", i, j, recvbuf[i*COUNT+j], (i + (rank * j)));*/
                    my_assert(recvbuf[i*COUNT+j] == (i + (rank * j)));
                }
            }
            break;

        case 20: /* basic pt2pt MPI_Isend/MPI_Irecv pairing */
            /* even ranks send to odd ranks, but only if we have a full pair */
            if ((rank % 2 != 0) || (rank != size-1)) {
                for (j = 0; j < COUNT; ++j) {
                    /* only odd procs did a recv */
                    if (rank % 2 == 0) {
                        my_assert(recvbuf[j] == 0xdeadbeef);
                    }
                    else {
                        if (recvbuf[j] != j) printf("recvbuf[%d]=%d j=%d\n", j, recvbuf[j], j);
                        my_assert(recvbuf[j] == j);
                    }
                }
            }
            break;

        default:
            printf("invalid case_num (%d) detected\n", l->case_num);
            assert(0);
            break;
    }
}
コード例 #16
0
ファイル: my_time.c プロジェクト: yp/Heu-MCHC
const char*
MYTIME_getname(pmytime pt)
{
  my_assert(pt!=NULL);
  return pt->timer_name;
}
コード例 #17
0
ファイル: glmain.cpp プロジェクト: JGelpi97/School
void parse_obj(char *buffer){
	OBJECT *po;
	char *pshape, *pshine, *pemi, *pamb, *pdiff, *pspec, *ptranslate, *pscale, *protate;
	Shape *s = NULL;


	my_assert ((num_objects < NUM_OBJECTS), "too many objects");
	po = &my_objects[num_objects++];

	pshape  = strtok(buffer, " ");
	//printf("pshape is %s\n",pshape);

	ptranslate    = strtok(NULL, "()");  strtok(NULL, "()");
	pscale        = strtok(NULL, "()");  strtok(NULL, "()"); 
	protate       = strtok(NULL, "()");  strtok(NULL, "()");  

	pshine  = strtok(NULL, "()");strtok(NULL, "()");
	//printf("pshine is %s\n",pshine);

	pemi    = strtok(NULL, "()");  strtok(NULL, "()"); 
	pamb    = strtok(NULL, "()");  strtok(NULL, "()"); 
	pdiff   = strtok(NULL, "()");  strtok(NULL, "()"); 
	pspec   = strtok(NULL, "()");  strtok(NULL, "()"); 


	po->sid  = atoi(pshape);
	po->shine = atof(pshine);

	parse_floats(ptranslate, po->translate);
	parse_floats(pscale, po->scale);
	parse_floats(protate, po->rotate);

	parse_floats(pemi, po->emi);
	parse_floats(pamb, po->amb);
	parse_floats(pdiff, po->diff);
	parse_floats(pspec, po->spec);

	//Create the shape
	switch (po->sid)
	{
		case 1: //cube
		{
			s = new Shape(CUBE, 1, 1, 1, 1);
			break;
		}
		case 2:	//house
		{
			s = new Shape(HOUSE, 1, 1, 1, 1);
			break;
		}
		case 3:
		{
			s = new Shape(SPHERE, 1, 1, 25, 25);
			break;
		}
		case 4:
		{
			s = new Shape(CYLINDER, 1, 1, 10, 10);
			break;
		}
		case 5:
		{
			s = new Shape(CONE, 1, 1, 10, 10);
			break;
		}
		case 6:	//Torus
		{
			s = new Shape(1.2, .2, 15, 40);
			break;
		}

	}
	if (s != NULL)
		s->switchRenderMode();

	// scale, rotate, translate the shape using the struct values
	real_scaling(s, po->scale[0], po->scale[1], po->scale[2]);  
	real_rotation(s, po->rotate[0], 1, 0, 0);
	real_rotation(s, po->rotate[1], 0, 1, 0);
	real_rotation(s, po->rotate[2], 0, 0, 1);
	real_translation(s, po->translate[0], po->translate[1], po->translate[2]);
	
	//Add to list
	shapeList.push_back(s);

	printf("read object\n");
}
コード例 #18
0
int main() {

	  int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, 
	       sea_hag, tribute, smithy};

	  int i, players, player, handCount, deckCount, discardCount, seed, address, return_val;
	  //struct gameState state;
	  struct gameState state;


	  printf("Running Random Adventurer Test\n");

	  /*
										--- Author's Note ---
	  So, I had problems running out of memory when I used the same gameState variable more than 12 times, and
	  I honestly don't know why. I momentarily solved this problem by adding more for loops and creating more gamestates;
	  I was still able to get decent coverage, though not up to the amount of tests I originally had in mind.

	  */

	  for (i = 0; i < MAX_TESTS; i++) {
	   players = rand() % 4;

	   seed = rand();		//pick random seed
		
	   initializeGame(players, k, seed, &state);	//initialize Gamestate 

	   //Initiate valid state variables
		  player = state.whoseTurn;
		  state.deckCount[player] = rand() % MAX_DECK; //Pick random deck size out of MAX DECK size
		  state.discardCount[player] = rand() % MAX_DECK;
		  state.handCount[player] = rand() % MAX_HAND;


		  //1 in 3 chance of making empty deck for coverage
		  if (seed % 3 == 0) {
			  state.deckCount[player] = 0;
		  }

		  //Copy state variables
		  handCount = state.handCount[player];
		  deckCount = state.deckCount[player];
		  discardCount = state.discardCount[player];

		  return_val = cardEffect(adventurer, 1, 1, 1, &state, 0, &address);		//Run adventurer card

		  //(1) check for return value of zero
		  my_assert( return_val == 0, "Non-zero value returned from function");
		  //(2) increase in discardCount should be same as decrease in deckCount
		  printf("discardCount: %d\nstate.discardCount: %d\ndeckCount: %d\nstate.deckCount: %d\n\n", discardCount, state.discardCount[player], deckCount, state.deckCount[player]);
		  if (deckCount != 0) {
			  my_assert( (state.discardCount[player] - discardCount) == (deckCount - state.deckCount[player] -2), "Increase in discardCount doesn't match decrease in deckCount");
			  //(3) make sure handCount variable increases by two
			  my_assert( state.handCount[player] == handCount + 2, "handCount was not increased by two");
		  }

	  }
	  
//	   for (i = 0; i < MAX_TESTS; i++) {
//
//  		  players = rand() % 4;
//		  seed = rand();		//pick random seed
//
//		  initializeGame(players, k, seed, &stat);	//initialize Gamestate
//
//		  //Initiate valid state variables
//		  stat.deckCount[player] = rand() % MAX_DECK; //Pick random deck size out of MAX DECK size
//		  stat.discardCount[player] = rand() % MAX_DECK;
//		  stat.handCount[player] = rand() % MAX_HAND;
//
//
//		  //Copy state variables
//		  handCount = stat.handCount[player];
//		  deckCount = stat.deckCount[player];
//
//		  //1 in 3 chance of making empty deck for coverage
//		  if (seed % 3 == 0) {
//
//			stat.deckCount[player] = 0;
//		  }
//
//		  cardEffect(adventurer, 1, 1, 1, &stat);		//Run adventurer card
//	  }
//
//	   for (i = 0; i < MAX_TESTS; i++) {
//
//  		  players = rand() % 4;
//		  seed = rand();		//pick random seed
//
//		  initializeGame(players, k, seed, &sta);	//initialize Gamestate
//
//		  //Initiate valid state variables
//		  sta.deckCount[player] = rand() % MAX_DECK; //Pick random deck size out of MAX DECK size
//		  sta.discardCount[player] = rand() % MAX_DECK;
//		  sta.handCount[player] = rand() % MAX_HAND;
//
//
//		  //Copy state variables
//		  handCount = sta.handCount[player];
//		  deckCount = sta.deckCount[player];
//
//		  //1 in 3 chance of making empty deck for coverage
//		  if (seed % 3 == 0) {
//
//			sta.deckCount[player] = 0;
//		  }
//		  cardEffect(adventurer, 1, 1, 1, &sta);		//Run adventurer card
//
//	   }

	  printf("Tests Complete\n");

	  return 0;
}
コード例 #19
0
ファイル: my_time.c プロジェクト: yp/Heu-MCHC
void
MYTIME_destroy(pmytime pt) 
{
  my_assert(pt!=NULL);
  pfree(pt);
}
コード例 #20
0
ファイル: wi_winma.c プロジェクト: j13s/devil
/* Draw the window wi in the foreground and save the background. */
void wi_drawwin(struct wi_window *wi) {
    int titlebar, x;
    struct node *n;


    my_assert(wi != NULL);
    titlebar =
        ( ( wi->w.buttons & (wb_drag | wb_size | wb_close) ) != 0 ||
         wi->w.title != NULL );

    if (wi->w.shrunk && !titlebar) {
        wi->w.shrunk = 0;
    }

    wi->win_contents =
        ( (!wi->w.shrunk &&
           wi->w.ysize >= shapes.titlebar_height * 2) || !titlebar );

    if (wi->bg) {
        ws_freebitmap(wi->bg);
    }

    checkmem( wi->bg =
                 ws_savebitmap(NULL, wi->w.xpos, wi->w.ypos, wi->w.xsize,
                               wi->w.ysize) );

    if (wi->win_contents) {
        ws_drawbox(w_xwinincoord(&wi->w, -1), w_ywinincoord(&wi->w, -1),
                   w_xwininsize(&wi->w) + 2, w_ywininsize(&wi->w) + 2,
                   notes.colindex[wi ==
                                  notes.cur_win ? cv_curwin : cv_winedge], 0);
        ws_drawfilledbox(w_xwinincoord(&wi->w, 0), w_ywinincoord(&wi->w, 0),
                         w_xwininsize(&wi->w), w_ywininsize(
                             &wi->w), notes.colindex[cv_winfill], 0);
    }

    for (n = wi->buttonlist.head; n->next != NULL && n->d.w_b->sys_button;
         n = n->next) {
        wi_drawbutton(n->d.w_b, 0);
    }

    if (titlebar) {
        if ( !( wi->w.buttons & (wb_drag | wb_size) ) ) {
            if ( !( wi->w.buttons & (wb_close | wb_shrink) ) ) {
                ws_drawfilledbox(
                    x = wi->w.xpos, wi->w.ypos, wi->w.xsize,
                    shapes.titlebar_height,
                    notes.colindex[notes.cur_win ==
                                   wi ? cv_curwin : cv_buttonin],
                    0);
            }
            else {
                ws_drawfilledbox(
                    x = wi->w.xpos + shapes.closebutton_width, wi->w.ypos,
                    wi->w.xsize - shapes.closebutton_width,
                    shapes.titlebar_height,
                    notes.colindex[notes.cur_win ==
                                   wi ? cv_curwin : cv_buttonin], 0);
            }

            ws_drawtext(x + 4, wi->w.ypos + 2, wi->w.xpos + wi->w.xsize - x -
                        6,
                        wi->w.title, notes.colindex[cv_textbg],
                        -1);
            ws_drawtext(x + 3, wi->w.ypos + 1, wi->w.xpos + wi->w.xsize - x -
                        6,
                        wi->w.title, notes.colindex[cv_textfg],
                        -1);
        }
    }

    wi->drawn = 1;

    if (wi->win_contents) {
        switch (wi->w.refresh) {
            case wr_routine:
                wi->w.refresh_routine(&wi->w, wi->w.data);
                break;

            case wr_normal:

                if (wi->in != NULL) {
                    ws_copybitmap(NULL, w_xwinincoord(&wi->w,
                                                      0),
                                  w_ywinincoord(&wi->w, 0),
                                  wi->in, 0, 0, w_xwininsize(
                                      &wi->w) >
                                  wi->in->xsize ? wi->in->xsize :
                                  w_xwininsize(&wi->w), w_ywininsize(
                                      &wi->w) > wi->in->ysize ?
                                  wi->in->xsize : w_ywininsize(&wi->w), 1);
                    ws_freebitmap(wi->in);
                    wi->in = NULL;
                }

                break;

            default:
                fprintf(errf, "Unknown refresh-type in drawwin: %d\n",
                        wi->w.refresh);
        }
    }
}
コード例 #21
0
ファイル: block.cpp プロジェクト: PCDS/paraDSRC
// ********************************************************************************************
void Block::Read(BitStream &bit_stream, LzMatcher &lz_matcher, std::vector<Field> &fields, uint32 n_fields,
	uint32 fastq_flags, std::vector<uchar> &symbols, HuffmanEncoder *Huffman_sym,
	std::vector<uchar> &qualities, std::vector<HuffmanEncoder*> &Huffman_qua, 
	uint32 max_run_len, std::vector<HuffmanEncoder*> &Huffman_run, uint32 n_qualities, 
	uint32 _global_max_sequence_length, uint32 max_quality_length, uint32 block_no, 
	uint32 quality_stats_mode, bool extracting)
{
	global_max_sequence_length = _global_max_sequence_length;

#if (D_RESERVE_BYTES_PER_BLOCK)
	{
		uchar bytes[Block::RESERVED_BYTES];
		bit_stream.GetBytes(bytes, Block::RESERVED_BYTES);
		for (uint32 i = 0; i < Block::RESERVED_BYTES; ++i)
		{
			my_assert(bytes[i] == INVALID_BYTE);
		}
	}
#endif

	no_of_amb.resize(rec_count);
	for (uint32 i = 0; i < rec_count; ++i)
	{
		records[i].Reset();
		no_of_amb[i] = 0;
	}

	int32 quality_len_bits = BitStream::BitLength(max_quality_length);
	if ((fastq_flags & FLAG_PLUS_ONLY) == 0)
	{
		for (uint32 i = 0; i < rec_count; ++i)
		{
			bit_stream.GetBit(records[i].plus_len);
		}
	}
	else
	{
		for (uint32 i = 0; i < rec_count; ++i)
		{
			records[i].plus_len = 1;
		}
	}

	if ((fastq_flags & FLAG_VARIABLE_LENGTH) != 0)
	{
		uint32 tmp;
		for (uint32 i = 0; i < rec_count; ++i)
		{
			FastqRecord& rec = records[i];
			bit_stream.GetBits(tmp, quality_len_bits);
			rec.quality_len = tmp;
			rec.ExtendTo(rec.quality, rec.quality_size, tmp+2);
			rec.sequence_len = tmp;
			rec.ExtendTo(rec.sequence, rec.sequence_size, tmp+2);
		}
	}
	else
	{
		for (uint32 i = 0; i < rec_count; ++i)
		{
			FastqRecord& rec = records[i];
			rec.quality_len = max_quality_length;
			rec.ExtendTo(rec.quality, rec.quality_size, max_quality_length+2);
			rec.sequence_len = global_max_sequence_length;
			rec.ExtendTo(rec.sequence, rec.sequence_size, global_max_sequence_length+2);
		}
	}

	if ((fastq_flags & FLAG_LINE_BREAKS) != 0)
	{
		uint32 line_breaks_bits;
		bit_stream.GetBits(line_breaks_bits, 5);
		uint32 tmp;

		for (uint32 i = 0; i < rec_count; ++i)
		{
			FastqRecord& rec = records[i];
			if (rec.sequence_breaks)
			{
				delete rec.sequence_breaks;
				rec.sequence_breaks = NULL;
			}

			bit_stream.GetBits(tmp, line_breaks_bits);
			while (tmp != 0)
			{
				if (!rec.sequence_breaks)
				{
					rec.sequence_breaks = new std::vector<int>;
				}
				rec.sequence_breaks->push_back(tmp);

				bit_stream.GetBits(tmp, line_breaks_bits);
			}


			if (rec.quality_breaks)
			{
				delete rec.quality_breaks;
				rec.quality_breaks = NULL;
			}
			bit_stream.GetBits(tmp, line_breaks_bits);
			while (tmp != 0)
			{
				if (!rec.quality_breaks)
				{
					rec.quality_breaks = new std::vector<int>;
				}
				rec.quality_breaks->push_back(tmp);

				bit_stream.GetBits(tmp, line_breaks_bits);
			}
		}
	}
	bit_stream.FlushInputWordBuffer();


	bool is_num_fields_constant = (fastq_flags & FLAG_CONST_NUM_FIELDS) != 0;
	ReadTitle(bit_stream, fields, n_fields, block_no, is_num_fields_constant);

	if (quality_stats_mode == QUALITY_RLE)
	{
		ReadQualityRLE(bit_stream, qualities, Huffman_qua, n_qualities, Huffman_run, max_run_len);
		MakeUnRLE();
	}
	else
	{
		bool use_trunc_h = quality_stats_mode == QUALITY_PLAIN_TRUNC;
		bool uses_const_delta = (fastq_flags & (FLAG_USE_DELTA | FLAG_DELTA_CONSTANT)) ==  (FLAG_USE_DELTA | FLAG_DELTA_CONSTANT);
		ReadQualityPlain(bit_stream, qualities, Huffman_qua, n_qualities, use_trunc_h, uses_const_delta);
	}

	bool try_lz = (fastq_flags & FLAG_TRY_LZ) != 0;
	if ((fastq_flags & FLAG_DNA_PLAIN) != 0)
	{
		ReadDNAPlain(bit_stream, lz_matcher, symbols, try_lz, extracting);
	}
	else
	{
		ReadDNAHuf(bit_stream, lz_matcher, symbols, Huffman_sym, try_lz, extracting);	// lz_matches not supported when Huffman encoding
	}

#if (D_COMPUTE_RECORDS_CRC_PER_BLOCK)
	uint32 hash;
	bit_stream.GetWord(hash);
	my_assert(hash == ComputeRecordsCrc32());
#endif
}
コード例 #22
0
int main() 
{

	int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, 
	    sea_hag, tribute, smithy};

	int i, j, player, handCount, deckCount, numActions, randomSeed;
	struct gameState state;

	printf("Running Random Adventurer Test\n\n");

	  /*
										--- Author's Note ---
	  So, I had problems running out of memory when I used the same gameState variable more than 12 times, and
	  I honestly don't know why. I momentarily solved this problem by adding more for loops and creating more gamestates;
	  I was still able to get decent coverage, though not up to the amount of tests I originally had in mind.

	  */
	
	for (i = 0; i < NUM_TESTS; i++) 
	{

		player = rand() % 3 + 2; //not less than 2 or greater than 4 players

	   	randomSeed = rand();		//pick random randomSeed
		
	   	initializeGame(player, k, randomSeed, &state);	//initialize Gamestate 

	   	//Initiate valid state variables
		state.deckCount[player] = rand() % MAX_DECK; //Pick random deck size out of MAX DECK size
		state.discardCount[player] = rand() % MAX_DECK;
		state.handCount[player] = rand() % MAX_HAND;
		state.numActions = (rand() % 10) + 1;

		//Copy state variables
		handCount = state.handCount[player];
		deckCount = state.deckCount[player];
		numActions = state.numActions;
		
		//1 in 3 chance of making empty deck for coverage ?
		if (randomSeed % 3 == 0)
		{
			state.deckCount[player] = 0;
		}
		
		//randomize the card piles
        for (j = 0; j < state.deckCount[player]; j++)
        {
            state.deck[player][j] = rand() % treasure_map;
        }
        for (j = 0; j < state.discardCount[player]; j++)
        {
            state.discard[player][j] = rand() % treasure_map;
        }
		for (j = 0; j < state.handCount[player]; j++)
		{
            state.hand[player][j] = rand() % treasure_map;
        }

		cardEffect(adventurer, 1, 1, 1, &state);		//Run adventurer card
		
		
		my_assert(handCount == state.handCount[player] - 1, "Handcount.");
		my_assert(numActions == state.numActions, "Actions.");
		
		
		printf("\n");
	}
	  
	
	printf("\nTests Complete\n");

	return 0;
}
コード例 #23
0
ファイル: glmain.c プロジェクト: Choino/school
void parse_obj(char *buffer){
	OBJECT *po;
	char *pshape, *pshine, *pemi, *pamb, *pdiff, *pspec, *ptranslate, *pscale, *protate;
	
	my_assert ((num_objects < NUM_OBJECTS), "too many objects");
	po = &my_objects[num_objects++];
	
	pshape  = strtok(buffer, " ");
	//printf("pshape is %s\n",pshape);
	
	ptranslate    = strtok(NULL, "()");  strtok(NULL, "()");
	pscale        = strtok(NULL, "()");  strtok(NULL, "()"); 
	protate       = strtok(NULL, "()");  strtok(NULL, "()");  
	
	pshine  = strtok(NULL, "()");strtok(NULL, "()");
	//printf("pshine is %s\n",pshine);
	
	pemi    = strtok(NULL, "()");  strtok(NULL, "()"); 
	pamb    = strtok(NULL, "()");  strtok(NULL, "()"); 
	pdiff   = strtok(NULL, "()");  strtok(NULL, "()"); 
	pspec   = strtok(NULL, "()");  strtok(NULL, "()"); 
	
	po->sid  = atoi(pshape);
	printf("%d",po->sid);
	po->shine = atof(pshine);
	
	parse_floats(ptranslate, po->translate);
	parse_floats(pscale, po->scale);
	parse_floats(protate, po->rotate);
	
	parse_floats(pemi, po->emi);
	parse_floats(pamb, po->amb);
	parse_floats(pdiff, po->diff);
	parse_floats(pspec, po->spec);
	
	// use switch to create your objects, cube given as example
	switch (po->sid){
		case 0: // makes house
			make_house(po);
			break;
		case 1: //cube
			make_cube_smart(po, 1);
			break;
		case 2:
			make_sphere(po, 1);
			break;
		case 3:
			make_cone(po, 1, 1);
			break;
		case 4:
			make_torus(po, 1.2, .1);
			break;
	}
	
	// scale, rotate, translate using your real tranformations from assignment 3 depending on input from spec file
	
	real_scaling(po, po->scale[0], po->scale[1], po->scale[2]);  
	real_rotation(po, po->rotate[0], 1, 0, 0);
	real_rotation(po, po->rotate[1], 0, 1, 0);
	real_rotation(po, po->rotate[2], 0, 0, 1);
	real_translation(po, po->translate[0], po->translate[1], po->translate[2]);
	
	printf("read object\n");
}
コード例 #24
0
int main(int argc, char **argv)
{
    int errs = 0;
    int i;
    int rank, size;
    int *sbuf = NULL;
    int *rbuf = NULL;
    int *scounts = NULL;
    int *rcounts = NULL;
    int *sdispls = NULL;
    int *rdispls = NULL;
    MPI_Datatype *types = NULL;
    MPI_Comm comm;

    /* intentionally not using MTest_Init/MTest_Finalize in order to make it
     * easy to take this test and use it as an NBC sanity test outside of the
     * MPICH test suite */
    MPI_Init(&argc, &argv);

    comm = MPI_COMM_WORLD;

    MPI_Comm_size(comm, &size);
    MPI_Comm_rank(comm, &rank);

    MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);

    /* enough space for every process to contribute at least NUM_INTS ints to any
     * collective operation */
    sbuf = malloc(NUM_INTS * size * sizeof(int));
    my_assert(sbuf);
    rbuf = malloc(NUM_INTS * size * sizeof(int));
    my_assert(rbuf);
    scounts = malloc(size * sizeof(int));
    my_assert(scounts);
    rcounts = malloc(size * sizeof(int));
    my_assert(rcounts);
    sdispls = malloc(size * sizeof(int));
    my_assert(sdispls);
    rdispls = malloc(size * sizeof(int));
    my_assert(rdispls);
    types = malloc(size * sizeof(MPI_Datatype));
    my_assert(types);

    for (i = 0; i < size; ++i) {
        sbuf[2 * i] = i;
        sbuf[2 * i + 1] = i;
        rbuf[2 * i] = i;
        rbuf[2 * i + 1] = i;
        scounts[i] = NUM_INTS;
        rcounts[i] = NUM_INTS;
        sdispls[i] = i * NUM_INTS;
        rdispls[i] = i * NUM_INTS;
        types[i] = MPI_INT;
    }

    if (rank == 0 && MPI_SUCCESS ==
        MPI_Gather(sbuf, NUM_INTS, MPI_INT, sbuf, NUM_INTS, MPI_INT, 0, comm))
        errs++;

    if (rank == 0 && MPI_SUCCESS ==
        MPI_Gatherv(sbuf, NUM_INTS, MPI_INT, sbuf, rcounts, rdispls, MPI_INT, 0, comm))
        errs++;

    if (rank == 0 && MPI_SUCCESS ==
        MPI_Scatter(sbuf, NUM_INTS, MPI_INT, sbuf, NUM_INTS, MPI_INT, 0, comm))
        errs++;

    if (rank == 0 && MPI_SUCCESS ==
        MPI_Scatterv(sbuf, scounts, sdispls, MPI_INT, sbuf, NUM_INTS, MPI_INT, 0, comm))
        errs++;

    if (MPI_SUCCESS == MPI_Allgather(&sbuf[rank], 1, MPI_INT, sbuf, 1, MPI_INT, comm))
        errs++;

    if (MPI_SUCCESS ==
        MPI_Allgatherv(&sbuf[rank * rcounts[rank]], rcounts[rank], MPI_INT, sbuf, rcounts, rdispls,
                       MPI_INT, comm))
        errs++;

    if (MPI_SUCCESS == MPI_Alltoall(sbuf, NUM_INTS, MPI_INT, sbuf, NUM_INTS, MPI_INT, comm))
        errs++;

    if (MPI_SUCCESS ==
        MPI_Alltoallv(sbuf, scounts, sdispls, MPI_INT, sbuf, scounts, sdispls, MPI_INT, comm))
        errs++;

    if (MPI_SUCCESS ==
        MPI_Alltoallw(sbuf, scounts, sdispls, types, sbuf, scounts, sdispls, types, comm))
        errs++;

    if (rank == 0 && MPI_SUCCESS == MPI_Reduce(sbuf, sbuf, NUM_INTS, MPI_INT, MPI_SUM, 0, comm))
        errs++;

    if (MPI_SUCCESS == MPI_Allreduce(sbuf, sbuf, NUM_INTS, MPI_INT, MPI_SUM, comm))
        errs++;

    if (MPI_SUCCESS == MPI_Reduce_scatter(sbuf, sbuf, rcounts, MPI_INT, MPI_SUM, comm))
        errs++;

    if (MPI_SUCCESS == MPI_Reduce_scatter_block(sbuf, sbuf, NUM_INTS, MPI_INT, MPI_SUM, comm))
        errs++;

    if (MPI_SUCCESS == MPI_Scan(sbuf, sbuf, NUM_INTS, MPI_INT, MPI_SUM, comm))
        errs++;

    if (MPI_SUCCESS == MPI_Exscan(sbuf, sbuf, NUM_INTS, MPI_INT, MPI_SUM, comm))
        errs++;

    if (sbuf)
        free(sbuf);
    if (rbuf)
        free(rbuf);
    if (scounts)
        free(scounts);
    if (rcounts)
        free(rcounts);
    if (sdispls)
        free(sdispls);
    if (rdispls)
        free(rdispls);
    if (types)
        free(types);

    if (rank == 0) {
        if (errs)
            fprintf(stderr, "Found %d errors\n", errs);
        else
            printf(" No errors\n");
    }
    MPI_Finalize();
    return 0;
}
コード例 #25
0
ファイル: cq_mysql_cmd.c プロジェクト: powersaven/checkQ
int mysql_select(eng_ctx_t* eng_ctx) {
    int ret = 0;

    MYSQL* wmysql;
    MYSQL* rmysql;       

    MYSQL_RES* wmysql_result;  
    MYSQL_RES* rmysql_result;
   
    MYSQL_ROW wrow;
    MYSQL_ROW rrow;
    int wnum_fields;
    int rnum_fields;
    int wnum_rows;
    int rnum_rows;

    size_t* wlengths;
    size_t* rlengths;

    wmysql = get_server_mysql(eng_ctx->write_server); 
    ret = mysql_select_db(wmysql, database);
    if (ret != 0) {
        return ret;
    }

    sql_gen(eng_ctx, SELECT);
    my_assert(eng_ctx->sql);
    
    const char* sql = eng_ctx->sql;
    
    // get pre data value from write server
    ret = mysql_real_query(wmysql, sql, strlen(sql));
    if (ret != 0) {
        log_debug("%s", mysql_error(wmysql));
        return ret;
    }

    eng_ctx->stats.nselect++;       
    g_stat.nselect = __sync_add_and_fetch(&g_stat.nselect, 1);

    wmysql_result = mysql_store_result(wmysql);
    wnum_fields   = mysql_num_fields(wmysql_result);
    wnum_rows     = mysql_num_rows(wmysql_result);
    wrow          = mysql_fetch_row(wmysql_result);
    wlengths      = mysql_fetch_lengths(wmysql_result);

    if (0 == wnum_rows) {
        mysql_free_result(wmysql_result);
        return 1;       // this obj do not exist in mysql
    }

    // get data from other nodes    
    for (int i = 0; i < eng_ctx->nread_server; i++) {
        rmysql = get_server_mysql(eng_ctx->read_servers[i]);       
        ret = mysql_select_db(rmysql, database);

        if (ret != 0) {
            log_warn("can not connect to server:%s, db:%s", 
                get_server_name(eng_ctx->read_servers[i]), database);
            continue;
        }

        ret = mysql_real_query(rmysql, sql, strlen(sql));
        if (ret != 0) {
            log_debug("%s", mysql_error(rmysql));
            continue;
        }

        set_sql_read_time(eng_ctx);
        eng_ctx->stats.nselect++;       
        g_stat.nselect = __sync_add_and_fetch(&g_stat.nselect, 1);

        rmysql_result = mysql_store_result(rmysql);
        rnum_fields   = mysql_num_fields(rmysql_result);
        rnum_rows     = mysql_num_rows(rmysql_result);
        rrow          = mysql_fetch_row(rmysql_result);
        rlengths      = mysql_fetch_lengths(rmysql_result);

        if (rnum_rows > 0) {
            for (int j = 0; j < wnum_fields; j++) {
                if (strncmp(wrow[j], rrow[j], wlengths[j]) != 0) {

#ifdef READABLE_DATA_LOG
                    char* logbuf_offset = eng_ctx->data_inconsist_log_buf; 
                    
                    logbuf_offset += sprintf(logbuf_offset, 
                        "Check ERROR !!!\n");
                    logbuf_offset += sprintf(logbuf_offset, 
                        "Command: %s ", cmdtype_toString(eng_ctx->prev_cmd));
                    logbuf_offset += sprintf(logbuf_offset, 
                        "Host: %15s ", get_server_name(eng_ctx->write_server));
                    logbuf_offset += sprintf(logbuf_offset, 
                        "Table: %s ", get_table_name(eng_ctx->table));
                    logbuf_offset += sprintf(logbuf_offset, 
                        "Key: %.*s ", 20, wrow[0]);
                    logbuf_offset += sprintf(logbuf_offset, 
                        "Value: %.*s ...\n", 8, wrow[1]);

                    logbuf_offset += sprintf(logbuf_offset, "Command: SELECT ");
                    logbuf_offset += sprintf(logbuf_offset, 
                        "Host: %15s ", get_server_name(eng_ctx->read_servers[i]));
                    logbuf_offset += sprintf(logbuf_offset, 
                        "Table: %s ", get_table_name(eng_ctx->table));
                    logbuf_offset += sprintf(logbuf_offset, 
                        "Key: %.*s ", 20, rrow[0]);
                    logbuf_offset += sprintf(logbuf_offset, 
                        "Value: %.*s ...\n\n", 8, rrow[1]);

                    *(logbuf_offset) = '\0';

                    fprintf(stderr, "%s", eng_ctx->data_inconsist_log_buf);
#else
                    /*
                    log_error("Data inconsistent detected!");
                    log_error("Write server is %s, read server is %s", 
                            get_server_name(eng_ctx->write_server), 
                            get_server_name(eng_ctx->read_servers[i]));
                    log_error("Last command is %s", 
                            cmdtype_toString(eng_ctx->prev_cmd));
                    log_error("There are %lld microseconds since last successful" 
                            "sql request", diff_sql_write_read_time(eng_ctx));

                    abort();
                    */
#endif                    
                    g_stat.ncheck_fail = __sync_add_and_fetch(&g_stat.ncheck_fail, 1);
                    abort();
                    
                }

            }
        } 
        else {
#ifdef READABLE_DATA_LOG
                    char* logbuf_offset = eng_ctx->data_inconsist_log_buf; 
                    
                    logbuf_offset += sprintf(logbuf_offset, 
                        "Check ERROR !!!\n");
                    logbuf_offset += sprintf(logbuf_offset, 
                        "Command: %s ", cmdtype_toString(eng_ctx->prev_cmd));
                    logbuf_offset += sprintf(logbuf_offset, 
                        "Host: %15s ", get_server_name(eng_ctx->write_server));
                    logbuf_offset += sprintf(logbuf_offset, 
                        "Table: %s ", get_table_name(eng_ctx->table));
                    logbuf_offset += sprintf(logbuf_offset, 
                        "Key: %.*s ", 20, wrow[0]);
                    logbuf_offset += sprintf(logbuf_offset, 
                        "Value: %.*s ...\n", 8, wrow[1]);

                    logbuf_offset += sprintf(logbuf_offset, "Command: SELECT ");
                    logbuf_offset += sprintf(logbuf_offset, 
                        "Host: %15s ", get_server_name(eng_ctx->read_servers[i]));
                    logbuf_offset += sprintf(logbuf_offset, 
                        "Table: %s ", get_table_name(eng_ctx->table));
                    logbuf_offset += sprintf(logbuf_offset, "Key: NULL ");
                    logbuf_offset += sprintf(logbuf_offset, "Value: NULL \n\n"); 

                    *(logbuf_offset) = '\0';

                    fprintf(stderr, "%s", eng_ctx->data_inconsist_log_buf);
#else                 
            /*       
            log_error("Data inconsistent detected!");
            log_error("Write server is %s, read server is %s", 
                    get_server_name(eng_ctx->write_server), 
                    get_server_name(eng_ctx->read_servers[i]));
            log_error("Last command is %s", 
                    cmdtype_toString(eng_ctx->prev_cmd));
            log_error("There are %lld microseconds since last successful" 
                    "sql request", diff_sql_write_read_time(eng_ctx));

            abort();
            */
#endif   
            g_stat.ncheck_fail = __sync_add_and_fetch(&g_stat.ncheck_fail, 1);         
            abort();
        }

        mysql_free_result(rmysql_result);
    }   
    
    mysql_free_result(wmysql_result);
    return 0;
}
コード例 #26
0
ファイル: my_time.c プロジェクト: yp/Heu-MCHC
DTYPE
MYTIME_getinterval(pmytime pt)
{
  my_assert(pt!=NULL);
  return pt->interval;
}
コード例 #27
0
ファイル: readtxt.c プロジェクト: j13s/devil
/* reads texture ham_sd from file specified in texture in direction dir.
   if ham_sd==NULL, read pig_sd.
   dir=0 -> normal (origin left upper corner x+ y+).
   dir=1 -> 90ø   (origin right upper corner x- y+).
   dir=2 -> 180ø   (origin right lower corner x- y-).
   dir=3 -> 270ø    (origin left lower corner x+ y-). */
void readbitmap(char *dest, struct pig_txt *pig_sd, struct ham_txt *ham_sd,
                int dir)                                                    {
    struct pig_txt *sd = ham_sd ? ham_sd->pig : pig_sd;
    char *sbitmap, bitmap[64 * 64], *buffer, *fill, *nobytesinrow;
    unsigned int size;
    unsigned int i;
    int startx, starty, endx, endy, addx, addy, mx, my, x, y;
    float l, angle;
    struct ws_bitmap *bm;
    FILE *f;


    my_assert(sd != NULL);
    f = sd->f;

    if (f == NULL) {
        return;
    }

    if (sd->pigno < 0) {
        return;          /* Nothing or Default */
    }

    fseek(f, (long)sd->offset, SEEK_SET);

    if (sd->xsize != 64 || sd->ysize != 64) {
        printmsg("Texture (rdl: %d pig: %d name: %s) of wrong size: %d %d",
                 ham_sd ? ham_sd->rdlno : -1, sd->pigno, sd->name, sd->xsize,
                 sd->ysize);
        return;
    }

    switch (dir) {
        case 0:
            startx = starty = 0;
            addx = addy = 1;
            mx = 1;
            my = 64;
            break;

        case 1:
            startx = 63;
            starty = 0;
            addx = -1;
            addy = 1;
            mx = 64;
            my = 1;
            break;

        case 2:
            startx = starty = 63;
            addx = addy = -1;
            mx = 1;
            my = 64;
            break;

        case 3:
            startx = 0;
            starty = 63;
            addx = 1;
            addy = -1;
            mx = 64;
            my = 1;
            break;

        default:
            printmsg(TXT_READBMUNKNOWNDIR, dir);
            startx = starty = 0;
            addx = addy = 1;
            mx = 1;
            my = 64;
    }

    endx = 63 - startx;
    endy = 63 - starty;

    if ( (sd->type1 & 0x08) == 0 ) {
        y = starty - addy;

        do {
            y += addy;
            x = startx - addx;

            do {
                x += addx;

                if (fread(&bitmap[y * my + x * mx], 1, 1, f) != 1) {
                    printmsg("Can't read uncompressed bitmap.");
                    return;
                }
            } while (x != endx);
        } while (y != endy);
    }
    else {
        if (fread(&size, sizeof(unsigned long int), (size_t)1, f) != 1) {
            printmsg("Can't read size of compressed bitmap.");
            return;
        }

        checkmem( nobytesinrow = MALLOC( (size_t)sd->ysize ) );
        checkmem( buffer = MALLOC( (size_t)size - 4 - sd->ysize ) );

        if (fread(nobytesinrow, 1, (size_t)sd->ysize, f) != sd->ysize) {
            printmsg("Can't read nobytesinrow.");
            return;
        }                                           /* no need for this */

        if (fread(buffer, (int)size - 4 - sd->ysize, 1, f) != 1) {
            printmsg("Can't read compressed bitmap.");
            return;
        }

        y = starty - addy;
        fill = buffer;

        do {
            y += addy;
            x = startx - addx;

            do {
                if ( (*fill & 0xe0) == 0xe0 ) {
                    for (i = 0; i < (*fill & 0x1f); i++) {
                        if (x == endx) {
                            printmsg("Error reading compressed bitmap.");
                            return;
                        }

                        x += addx;
                        bitmap[y * my + x * mx] = *(fill + 1);
                    }

                    fill += 2;
                }
                else {
                    x += addx;
                    bitmap[y * my + x * mx] = *(fill++);
                }
            } while (x != endx);

            fill++; /*0xe0*/
        } while (y != endy);

        FREE(buffer);
        FREE(nobytesinrow);
    }

    for (fill = bitmap, sbitmap = dest; fill - bitmap < 64 * 64; fill++,
         sbitmap++) {
        if (*( (unsigned char *)fill ) != 0xff) {
            *sbitmap = *fill;
        }
    }

    /* draw the lines for the moved textures */
    if ( ham_sd != NULL && (ham_sd->xspeed != 0 || ham_sd->yspeed != 0) ) {
        switch (dir) {
            case 2:
                mx = ham_sd->xspeed;
                my = ham_sd->yspeed;
                break;

            case 3:
                mx = ham_sd->yspeed;
                my = -ham_sd->xspeed;
                break;

            case 0:
                mx = -ham_sd->xspeed;
                my = -ham_sd->yspeed;
                break;

            case 1:
                mx = -ham_sd->yspeed;
                my = ham_sd->xspeed;
                break;

            default:
                mx = ham_sd->xspeed;
                my = ham_sd->yspeed;
        }

        checkmem( bm = ws_createbitmap(64, 64, dest) );
        l = sqrt( (float)mx * mx + my * my );
        startx = 31 + 24 * mx / l;
        starty = 31 + 24 * my / l;
        angle = my >= 0 ? acos(mx / l) : -acos(mx / l);
        endx = 31 + 12 * cos(angle + ANIM_ARROW_ANGLE);
        endy = 31 + 12 * sin(angle + ANIM_ARROW_ANGLE);
        x = 31 + 12 * cos(angle - ANIM_ARROW_ANGLE);
        addx = 0;
        y = 31 + 12 * sin(angle - ANIM_ARROW_ANGLE);
        addy = 0;
        size = ( (mx < 0 ? -mx : mx) + (my < 0 ? -my : my) ) >> 7;

        for (i = 0; i < size; i++) {
            ws_bmdrawline(bm, startx + addx, starty + addy, endx + addx,
                          endy + addy,
                          view.color[WHITE],
                          0);
            ws_bmdrawline(bm, startx + addx, starty + addy, x + addx, y +
                          addy,
                          view.color[WHITE],
                          0);

            if (mx > 0) {
                addx -= 2;
            }
            else if (mx < 0) {
                addx += 2;
            }

            if (my > 0) {
                addy -= 2;
            }
            else if (my < 0) {
                addy += 2;
            }

            ws_bmdrawline(bm, startx + addx, starty + addy, endx + addx,
                          endy + addy,
                          view.color[BLACK],
                          0);
            ws_bmdrawline(bm, startx + addx, starty + addy, x + addx, y +
                          addy,
                          view.color[BLACK],
                          0);

            if (mx > 0) {
                addx -= 2;
            }
            else if (mx < 0) {
                addx += 2;
            }

            if (my > 0) {
                addy -= 2;
            }
            else if (my < 0) {
                addy += 2;
            }
        }

        ws_freebitmap(bm);
    }
}
コード例 #28
0
ファイル: nonblocking3.c プロジェクト: R7R8/simgrid
/* Starts a "random" operation on "comm" corresponding to "rndnum" and returns
 * in (*req) a request handle corresonding to that operation.  This call should
 * be considered collective over comm (with a consistent value for "rndnum"),
 * even though the operation may only be a point-to-point request. */
static void start_random_nonblocking(MPI_Comm comm, unsigned int rndnum, MPI_Request *req, struct laundry *l)
{
    int i, j;
    int rank, size;
    int *buf = NULL;
    int *recvbuf = NULL;
    int *sendcounts = NULL;
    int *recvcounts = NULL;
    int *sdispls = NULL;
    int *rdispls = NULL;
    int *sendtypes = NULL;
    int *recvtypes = NULL;
    signed char *buf_alias = NULL;

    MPI_Comm_rank(comm, &rank);
    MPI_Comm_size(comm, &size);

    *req = MPI_REQUEST_NULL;

    l->case_num = -1;
    l->comm = comm;

    l->buf        = buf        = malloc(COUNT*size*sizeof(int));
    l->recvbuf    = recvbuf    = malloc(COUNT*size*sizeof(int));
    l->sendcounts = sendcounts = malloc(size*sizeof(int));
    l->recvcounts = recvcounts = malloc(size*sizeof(int));
    l->sdispls    = sdispls    = malloc(size*sizeof(int));
    l->rdispls    = rdispls    = malloc(size*sizeof(int));
    l->sendtypes  = sendtypes  = malloc(size*sizeof(MPI_Datatype));
    l->recvtypes  = recvtypes  = malloc(size*sizeof(MPI_Datatype));

#define NUM_CASES (21)
    l->case_num = rand_range(rndnum, 0, NUM_CASES);
    switch (l->case_num) {
        case 0: /* MPI_Ibcast */
            for (i = 0; i < COUNT; ++i) {
                if (rank == 0) {
                    buf[i] = i;
                }
                else {
                    buf[i] = 0xdeadbeef;
                }
            }
            MPI_Ibcast(buf, COUNT, MPI_INT, 0, comm, req);
            break;

        case 1: /* MPI_Ibcast (again, but designed to stress scatter/allgather impls) */
            /* FIXME fiddle with PRIME and buffer allocation s.t. PRIME is much larger (1021?) */
            buf_alias = (signed char *)buf;
            my_assert(COUNT*size*sizeof(int) > PRIME); /* sanity */
            for (i = 0; i < PRIME; ++i) {
                if (rank == 0)
                    buf_alias[i] = i;
                else
                    buf_alias[i] = 0xdb;
            }
            for (i = PRIME; i < COUNT * size * sizeof(int); ++i) {
                buf_alias[i] = 0xbf;
            }
            MPI_Ibcast(buf_alias, PRIME, MPI_SIGNED_CHAR, 0, comm, req);
            break;

        case 2: /* MPI_Ibarrier */
            MPI_Ibarrier(comm, req);
            break;

        case 3: /* MPI_Ireduce */
            for (i = 0; i < COUNT; ++i) {
                buf[i] = rank + i;
                recvbuf[i] = 0xdeadbeef;
            }
            MPI_Ireduce(buf, recvbuf, COUNT, MPI_INT, MPI_SUM, 0, comm, req);
            break;

        case 4: /* same again, use a user op and free it before the wait */
            {
                MPI_Op op = MPI_OP_NULL;
                MPI_Op_create(sum_fn, /*commute=*/1, &op);
                for (i = 0; i < COUNT; ++i) {
                    buf[i] = rank + i;
                    recvbuf[i] = 0xdeadbeef;
                }
                MPI_Ireduce(buf, recvbuf, COUNT, MPI_INT, op, 0, comm, req);
                MPI_Op_free(&op);
            }
            break;

        case 5: /* MPI_Iallreduce */
            for (i = 0; i < COUNT; ++i) {
                buf[i] = rank + i;
                recvbuf[i] = 0xdeadbeef;
            }
            MPI_Iallreduce(buf, recvbuf, COUNT, MPI_INT, MPI_SUM, comm, req);
            break;

        case 6: /* MPI_Ialltoallv (a weak test, neither irregular nor sparse) */
            for (i = 0; i < size; ++i) {
                sendcounts[i] = COUNT;
                recvcounts[i] = COUNT;
                sdispls[i] = COUNT * i;
                rdispls[i] = COUNT * i;
                for (j = 0; j < COUNT; ++j) {
                    buf[i*COUNT+j] = rank + (i * j);
                    recvbuf[i*COUNT+j] = 0xdeadbeef;
                }
            }
            MPI_Ialltoallv(buf, sendcounts, sdispls, MPI_INT, recvbuf, recvcounts, rdispls, MPI_INT, comm, req);
            break;

        case 7: /* MPI_Igather */
            for (i = 0; i < size*COUNT; ++i) {
                buf[i] = rank + i;
                recvbuf[i] = 0xdeadbeef;
            }
            MPI_Igather(buf, COUNT, MPI_INT, recvbuf, COUNT, MPI_INT, 0, comm, req);
            break;

        case 8: /* same test again, just use a dup'ed datatype and free it before the wait */
            {
                MPI_Datatype type = MPI_DATATYPE_NULL;
                MPI_Type_dup(MPI_INT, &type);
                for (i = 0; i < size*COUNT; ++i) {
                    buf[i] = rank + i;
                    recvbuf[i] = 0xdeadbeef;
                }
                MPI_Igather(buf, COUNT, MPI_INT, recvbuf, COUNT, type, 0, comm, req);
                MPI_Type_free(&type); /* should cause implementations that don't refcount
                                         correctly to blow up or hang in the wait */
            }
            break;

        case 9: /* MPI_Iscatter */
            for (i = 0; i < size; ++i) {
                for (j = 0; j < COUNT; ++j) {
                    if (rank == 0)
                        buf[i*COUNT+j] = i + j;
                    else
                        buf[i*COUNT+j] = 0xdeadbeef;
                    recvbuf[i*COUNT+j] = 0xdeadbeef;
                }
            }
            MPI_Iscatter(buf, COUNT, MPI_INT, recvbuf, COUNT, MPI_INT, 0, comm, req);
            break;

        case 10: /* MPI_Iscatterv */
            for (i = 0; i < size; ++i) {
                /* weak test, just test the regular case where all counts are equal */
                sendcounts[i] = COUNT;
                sdispls[i] = i * COUNT;
                for (j = 0; j < COUNT; ++j) {
                    if (rank == 0)
                        buf[i*COUNT+j] = i + j;
                    else
                        buf[i*COUNT+j] = 0xdeadbeef;
                    recvbuf[i*COUNT+j] = 0xdeadbeef;
                }
            }
            MPI_Iscatterv(buf, sendcounts, sdispls, MPI_INT, recvbuf, COUNT, MPI_INT, 0, comm, req);
            break;

        case 11: /* MPI_Ireduce_scatter */
            for (i = 0; i < size; ++i) {
                recvcounts[i] = COUNT;
                for (j = 0; j < COUNT; ++j) {
                    buf[i*COUNT+j] = rank + i;
                    recvbuf[i*COUNT+j] = 0xdeadbeef;
                }
            }
            MPI_Ireduce_scatter(buf, recvbuf, recvcounts, MPI_INT, MPI_SUM, comm, req);
            break;

        case 12: /* MPI_Ireduce_scatter_block */
            for (i = 0; i < size; ++i) {
                for (j = 0; j < COUNT; ++j) {
                    buf[i*COUNT+j] = rank + i;
                    recvbuf[i*COUNT+j] = 0xdeadbeef;
                }
            }
            MPI_Ireduce_scatter_block(buf, recvbuf, COUNT, MPI_INT, MPI_SUM, comm, req);
            break;

        case 13: /* MPI_Igatherv */
            for (i = 0; i < size*COUNT; ++i) {
                buf[i] = 0xdeadbeef;
                recvbuf[i] = 0xdeadbeef;
            }
            for (i = 0; i < COUNT; ++i) {
                buf[i] = rank + i;
            }
            for (i = 0; i < size; ++i) {
                recvcounts[i] = COUNT;
                rdispls[i] = i * COUNT;
            }
            MPI_Igatherv(buf, COUNT, MPI_INT, recvbuf, recvcounts, rdispls, MPI_INT, 0, comm, req);
            break;

        case 14: /* MPI_Ialltoall */
            for (i = 0; i < size; ++i) {
                for (j = 0; j < COUNT; ++j) {
                    buf[i*COUNT+j] = rank + (i * j);
                    recvbuf[i*COUNT+j] = 0xdeadbeef;
                }
            }
            MPI_Ialltoall(buf, COUNT, MPI_INT, recvbuf, COUNT, MPI_INT, comm, req);
            break;

        case 15: /* MPI_Iallgather */
            for (i = 0; i < size*COUNT; ++i) {
                buf[i] = rank + i;
                recvbuf[i] = 0xdeadbeef;
            }
            MPI_Iallgather(buf, COUNT, MPI_INT, recvbuf, COUNT, MPI_INT, comm, req);
            break;

        case 16: /* MPI_Iallgatherv */
            for (i = 0; i < size; ++i) {
                for (j = 0; j < COUNT; ++j) {
                    recvbuf[i*COUNT+j] = 0xdeadbeef;
                }
                recvcounts[i] = COUNT;
                rdispls[i] = i * COUNT;
            }
            for (i = 0; i < COUNT; ++i)
                buf[i] = rank + i;
            MPI_Iallgatherv(buf, COUNT, MPI_INT, recvbuf, recvcounts, rdispls, MPI_INT, comm, req);
            break;

        case 17: /* MPI_Iscan */
            for (i = 0; i < COUNT; ++i) {
                buf[i] = rank + i;
                recvbuf[i] = 0xdeadbeef;
            }
            MPI_Iscan(buf, recvbuf, COUNT, MPI_INT, MPI_SUM, comm, req);
            break;

        case 18: /* MPI_Iexscan */
            for (i = 0; i < COUNT; ++i) {
                buf[i] = rank + i;
                recvbuf[i] = 0xdeadbeef;
            }
            MPI_Iexscan(buf, recvbuf, COUNT, MPI_INT, MPI_SUM, comm, req);
            break;

        case 19: /* MPI_Ialltoallw (a weak test, neither irregular nor sparse) */
            for (i = 0; i < size; ++i) {
                sendcounts[i] = COUNT;
                recvcounts[i] = COUNT;
                sdispls[i] = COUNT * i * sizeof(int);
                rdispls[i] = COUNT * i * sizeof(int);
                sendtypes[i] = MPI_INT;
                recvtypes[i] = MPI_INT;
                for (j = 0; j < COUNT; ++j) {
                    buf[i*COUNT+j] = rank + (i * j);
                    recvbuf[i*COUNT+j] = 0xdeadbeef;
                }
            }
            MPI_Ialltoallw(buf, sendcounts, sdispls, sendtypes, recvbuf, recvcounts, rdispls, recvtypes, comm, req);
            break;

        case 20: /* basic pt2pt MPI_Isend/MPI_Irecv pairing */
            /* even ranks send to odd ranks, but only if we have a full pair */
            if ((rank % 2 != 0) || (rank != size-1)) {
                for (j = 0; j < COUNT; ++j) {
                    buf[j] = j;
                    recvbuf[j] = 0xdeadbeef;
                }
                if (rank % 2 == 0)
                    MPI_Isend(buf, COUNT, MPI_INT, rank+1, 5, comm, req);
                else
                    MPI_Irecv(recvbuf, COUNT, MPI_INT, rank-1, 5, comm, req);
            }
            break;

        default:
            fprintf(stderr, "unexpected value for l->case_num=%d)\n", (l->case_num));
            MPI_Abort(comm, 1);
            exit(1);
            break;
    }
}
コード例 #29
0
ファイル: nonblocking.c プロジェクト: Niharikareddy/mpich
int main(int argc, char **argv)
{
    int errs = 0;
    int i;
    int rank, size;
    int *sbuf = NULL;
    int *rbuf = NULL;
    int *scounts = NULL;
    int *rcounts = NULL;
    int *sdispls = NULL;
    int *rdispls = NULL;
    int *types = NULL;
    MPI_Comm comm;
    MPI_Request req;

    /* intentionally not using MTest_Init/MTest_Finalize in order to make it
     * easy to take this test and use it as an NBC sanity test outside of the
     * MPICH test suite */
    MPI_Init(&argc, &argv);

    comm = MPI_COMM_WORLD;

    MPI_Comm_size(comm, &size);
    MPI_Comm_rank(comm, &rank);

    /* enough space for every process to contribute at least NUM_INTS ints to any
     * collective operation */
    sbuf = malloc(NUM_INTS * size * sizeof(int));
    my_assert(sbuf);
    rbuf = malloc(NUM_INTS * size * sizeof(int));
    my_assert(rbuf);
    scounts = malloc(size * sizeof(int));
    my_assert(scounts);
    rcounts = malloc(size * sizeof(int));
    my_assert(rcounts);
    sdispls = malloc(size * sizeof(int));
    my_assert(sdispls);
    rdispls = malloc(size * sizeof(int));
    my_assert(rdispls);
    types = malloc(size * sizeof(int));
    my_assert(types);

    for (i = 0; i < size; ++i) {
        sbuf[2 * i] = i;
        sbuf[2 * i + 1] = i;
        rbuf[2 * i] = i;
        rbuf[2 * i + 1] = i;
        scounts[i] = NUM_INTS;
        rcounts[i] = NUM_INTS;
        sdispls[i] = i * NUM_INTS;
        rdispls[i] = i * NUM_INTS;
        types[i] = MPI_INT;
    }

    MPI_Ibarrier(comm, &req);
    MPI_Wait(&req, MPI_STATUS_IGNORE);

    MPI_Ibcast(sbuf, NUM_INTS, MPI_INT, 0, comm, &req);
    MPI_Wait(&req, MPI_STATUS_IGNORE);

    MPI_Igather(sbuf, NUM_INTS, MPI_INT, rbuf, NUM_INTS, MPI_INT, 0, comm, &req);
    MPI_Wait(&req, MPI_STATUS_IGNORE);

    if (0 == rank)
        MPI_Igather(MPI_IN_PLACE, -1, MPI_DATATYPE_NULL, rbuf, NUM_INTS, MPI_INT, 0, comm, &req);
    else
        MPI_Igather(sbuf, NUM_INTS, MPI_INT, rbuf, NUM_INTS, MPI_INT, 0, comm, &req);
    MPI_Wait(&req, MPI_STATUS_IGNORE);

    MPI_Igatherv(sbuf, NUM_INTS, MPI_INT, rbuf, rcounts, rdispls, MPI_INT, 0, comm, &req);
    MPI_Wait(&req, MPI_STATUS_IGNORE);

    if (0 == rank)
        MPI_Igatherv(MPI_IN_PLACE, -1, MPI_DATATYPE_NULL, rbuf, rcounts, rdispls, MPI_INT, 0, comm,
                     &req);
    else
        MPI_Igatherv(sbuf, NUM_INTS, MPI_INT, rbuf, rcounts, rdispls, MPI_INT, 0, comm, &req);
    MPI_Wait(&req, MPI_STATUS_IGNORE);

    MPI_Iscatter(sbuf, NUM_INTS, MPI_INT, rbuf, NUM_INTS, MPI_INT, 0, comm, &req);
    MPI_Wait(&req, MPI_STATUS_IGNORE);

    if (0 == rank)
        MPI_Iscatter(sbuf, NUM_INTS, MPI_INT, MPI_IN_PLACE, -1, MPI_DATATYPE_NULL, 0, comm, &req);
    else
        MPI_Iscatter(sbuf, NUM_INTS, MPI_INT, rbuf, NUM_INTS, MPI_INT, 0, comm, &req);
    MPI_Wait(&req, MPI_STATUS_IGNORE);

    MPI_Iscatterv(sbuf, scounts, sdispls, MPI_INT, rbuf, NUM_INTS, MPI_INT, 0, comm, &req);
    MPI_Wait(&req, MPI_STATUS_IGNORE);

    if (0 == rank)
        MPI_Iscatterv(sbuf, scounts, sdispls, MPI_INT, MPI_IN_PLACE, -1, MPI_DATATYPE_NULL, 0, comm,
                      &req);
    else
        MPI_Iscatterv(sbuf, scounts, sdispls, MPI_INT, rbuf, NUM_INTS, MPI_INT, 0, comm, &req);
    MPI_Wait(&req, MPI_STATUS_IGNORE);

    MPI_Iallgather(sbuf, NUM_INTS, MPI_INT, rbuf, NUM_INTS, MPI_INT, comm, &req);
    MPI_Wait(&req, MPI_STATUS_IGNORE);

    MPI_Iallgather(MPI_IN_PLACE, -1, MPI_DATATYPE_NULL, rbuf, NUM_INTS, MPI_INT, comm, &req);
    MPI_Wait(&req, MPI_STATUS_IGNORE);

    MPI_Iallgatherv(sbuf, NUM_INTS, MPI_INT, rbuf, rcounts, rdispls, MPI_INT, comm, &req);
    MPI_Wait(&req, MPI_STATUS_IGNORE);

    MPI_Iallgatherv(MPI_IN_PLACE, -1, MPI_DATATYPE_NULL, rbuf, rcounts, rdispls, MPI_INT, comm,
                    &req);
    MPI_Wait(&req, MPI_STATUS_IGNORE);

    MPI_Ialltoall(sbuf, NUM_INTS, MPI_INT, rbuf, NUM_INTS, MPI_INT, comm, &req);
    MPI_Wait(&req, MPI_STATUS_IGNORE);

    MPI_Ialltoall(MPI_IN_PLACE, -1, MPI_DATATYPE_NULL, rbuf, NUM_INTS, MPI_INT, comm, &req);
    MPI_Wait(&req, MPI_STATUS_IGNORE);

    MPI_Ialltoallv(sbuf, scounts, sdispls, MPI_INT, rbuf, rcounts, rdispls, MPI_INT, comm, &req);
    MPI_Wait(&req, MPI_STATUS_IGNORE);

    MPI_Ialltoallv(MPI_IN_PLACE, NULL, NULL, MPI_DATATYPE_NULL, rbuf, rcounts, rdispls, MPI_INT,
                   comm, &req);
    MPI_Wait(&req, MPI_STATUS_IGNORE);

    MPI_Ialltoallw(sbuf, scounts, sdispls, types, rbuf, rcounts, rdispls, types, comm, &req);
    MPI_Wait(&req, MPI_STATUS_IGNORE);

    MPI_Ialltoallw(MPI_IN_PLACE, NULL, NULL, NULL, rbuf, rcounts, rdispls, types, comm, &req);
    MPI_Wait(&req, MPI_STATUS_IGNORE);

    MPI_Ireduce(sbuf, rbuf, NUM_INTS, MPI_INT, MPI_SUM, 0, comm, &req);
    MPI_Wait(&req, MPI_STATUS_IGNORE);

    if (0 == rank)
        MPI_Ireduce(MPI_IN_PLACE, rbuf, NUM_INTS, MPI_INT, MPI_SUM, 0, comm, &req);
    else
        MPI_Ireduce(sbuf, rbuf, NUM_INTS, MPI_INT, MPI_SUM, 0, comm, &req);
    MPI_Wait(&req, MPI_STATUS_IGNORE);

    MPI_Iallreduce(sbuf, rbuf, NUM_INTS, MPI_INT, MPI_SUM, comm, &req);
    MPI_Wait(&req, MPI_STATUS_IGNORE);

    MPI_Iallreduce(MPI_IN_PLACE, rbuf, NUM_INTS, MPI_INT, MPI_SUM, comm, &req);
    MPI_Wait(&req, MPI_STATUS_IGNORE);

    MPI_Ireduce_scatter(sbuf, rbuf, rcounts, MPI_INT, MPI_SUM, comm, &req);
    MPI_Wait(&req, MPI_STATUS_IGNORE);

    MPI_Ireduce_scatter(MPI_IN_PLACE, rbuf, rcounts, MPI_INT, MPI_SUM, comm, &req);
    MPI_Wait(&req, MPI_STATUS_IGNORE);

    MPI_Ireduce_scatter_block(sbuf, rbuf, NUM_INTS, MPI_INT, MPI_SUM, comm, &req);
    MPI_Wait(&req, MPI_STATUS_IGNORE);

    MPI_Ireduce_scatter_block(MPI_IN_PLACE, rbuf, NUM_INTS, MPI_INT, MPI_SUM, comm, &req);
    MPI_Wait(&req, MPI_STATUS_IGNORE);

    MPI_Iscan(sbuf, rbuf, NUM_INTS, MPI_INT, MPI_SUM, comm, &req);
    MPI_Wait(&req, MPI_STATUS_IGNORE);

    MPI_Iscan(MPI_IN_PLACE, rbuf, NUM_INTS, MPI_INT, MPI_SUM, comm, &req);
    MPI_Wait(&req, MPI_STATUS_IGNORE);

    MPI_Iexscan(sbuf, rbuf, NUM_INTS, MPI_INT, MPI_SUM, comm, &req);
    MPI_Wait(&req, MPI_STATUS_IGNORE);

    MPI_Iexscan(MPI_IN_PLACE, rbuf, NUM_INTS, MPI_INT, MPI_SUM, comm, &req);
    MPI_Wait(&req, MPI_STATUS_IGNORE);

    if (sbuf)
        free(sbuf);
    if (rbuf)
        free(rbuf);
    if (scounts)
        free(scounts);
    if (rcounts)
        free(rcounts);
    if (sdispls)
        free(sdispls);
    if (rdispls)
        free(rdispls);

    if (rank == 0) {
        if (errs)
            fprintf(stderr, "Found %d errors\n", errs);
        else
            printf(" No errors\n");
    }
    MPI_Finalize();
    return 0;
}
コード例 #30
0
ファイル: my_time.c プロジェクト: yp/Heu-MCHC
void
MYTIME_start(pmytime pt) {
  my_assert(pt!=NULL);
  pt->active= true;
  gettimeofday(&pt->start, NULL);
}