Exemple #1
0
int main(int argc, char **argv)
{
    static int *A, *B, *C, *D, *E, *F, *G;
    gasnet_node_t myproc, i;
    int pollers = 0;
    int j;
   
    /* call startup */
    GASNET_Safe(gasnet_init(&argc, &argv));

    int arg = 1;
    int help = 0;
    while (argc > arg) {
      if (!strcmp(argv[arg], "-p")) {
#if GASNET_PAR
        ++arg;
        if (argc > arg) { pollers = atoi(argv[arg]); arg++; }
        else help = 1;
#else
        if (0 == gasnet_mynode()) {
          fprintf(stderr, "testcoll %s\n", GASNET_CONFIG_STRING);
          fprintf(stderr, "ERROR: The -p option is only available in the PAR configuration.\n");
          fflush(NULL);
        }
        sleep(1);
        gasnet_exit(1);
#endif
      } else if (argv[arg][0] == '-') {
        help = 1;
        ++arg;
      } else break;
    }

    if (argc > arg) {
      iters = atoi(argv[arg]);
      ++arg;
    }
    if (iters < 1) {
      iters = 1000;
    }

#if GASNET_PAR
    if (argc > arg) {
      threads = atoi(argv[arg]);
      ++arg;
    }
    threads = test_thread_limit(threads);
    if (threads < 1) {
      printf("ERROR: Threads must be between 1 and %d\n", TEST_MAXTHREADS);
      exit(EXIT_FAILURE);
    }
#endif

    /* get SPMD info */
    myproc = gasnet_mynode();
    numprocs = gasnet_nodes();
    images = numprocs * threads;
    datasize = iters * (3 + 4 * images);

    GASNET_Safe(gasnet_attach(NULL, 0, TEST_SEGSZ_REQUEST, TEST_MINHEAPOFFSET));

#if GASNET_PAR
  #define USAGE "[options] (iters) (threadcnt)\n" \
                "  The -p option gives the number of polling threads, specified as\n" \
                "    a non-negative integer argument (default is no polling threads).\n"
#else
  #define USAGE "(iters)\n"
#endif
    test_init("testcoll",0,USAGE);

    TEST_SET_WAITMODE(threads + pollers);
    if (argc > arg || help) test_usage();
    
    MSG0("Running coll test(s) with %d iterations.", iters);

    R = test_malloc(iters*sizeof(int));

    /* Number if ints to store */

    /* Carve some variables out of the (aligned) segment: */
    Aw = test_malloc(iters * sizeof(int *));
    Bw = test_malloc(iters * sizeof(int *));
    Cw = test_malloc(iters * sizeof(int *));
    Dw = test_malloc(iters * sizeof(int *));
    Ew = test_malloc(iters * sizeof(int *));
    Fw = test_malloc(iters * sizeof(int *));
    Gw = test_malloc(iters * sizeof(int *));
    A = (int *)TEST_MYSEG();	/* int [1*iters] */
    B = A + 1*iters;		/* int [1*iters] */
    C = B + 1*iters;		/* int [N*iters] */
    D = C + images*iters;	/* int [N*iters] */
    E = D + images*iters;	/* int [1*iters] */
    F = E + 1*iters;		/* int [N*iters] */
    G = F + images*iters;	/* int [N*iters] */
    for (j = 0; j < iters; ++j) {
      Aw[j] = A + j;
      Bw[j] = B + j;
      Cw[j] = C + j*images;
      Dw[j] = D + j*images;
      Ew[j] = E + j;
      Fw[j] = F + j*images;
      Gw[j] = G + j*images;
    }

    /* The unaligned equivalents */
    Av = test_malloc_2D(iters, images * sizeof(int *));
    Bv = test_malloc_2D(iters, images * sizeof(int *));
    Cv = test_malloc_2D(iters, images * sizeof(int *));
    Dv = test_malloc_2D(iters, images * sizeof(int *));
    Ev = test_malloc_2D(iters, images * sizeof(int *));
    Fv = test_malloc_2D(iters, images * sizeof(int *));
    Gv = test_malloc_2D(iters, images * sizeof(int *));
    for (i = 0; i < images; ++i) {
      /* Using (TEST_SEG(n) + n) yields unaligned even when the segments are aligned.
         This is to help catch any case where addresses might have been misused that
         might go undetected if the addresses were aligned */
      A = (int *)TEST_SEG(i/threads) + (i/threads) + datasize*(i%threads);
      B = A + 1*iters;
      C = B + 1*iters;
      D = C + images*iters;
      E = D + images*iters;
      F = E + 1*iters;
      G = F + images*iters;
      for (j = 0; j < iters; ++j) {
	Av[j][i] = A + j;
	Bv[j][i] = B + j;
	Cv[j][i] = C + j*images;
	Dv[j][i] = D + j*images;
	Ev[j][i] = E + j;
	Fv[j][i] = F + j*images;
	Gv[j][i] = G + j*images;
      }
    }

    BARRIER();

#if GASNET_PAR
    MSG("Forking %d gasnet threads (%d active, %d polling)", threads+pollers, threads, pollers);
    {
        int i;
	thread_data_t* tt_thread_data = test_malloc(threads*sizeof(thread_data_t));
        for (i = 0; i < threads; i++) {
	    tt_thread_data[i].myproc = myproc;
	    tt_thread_data[i].local_id = i;
	    tt_thread_data[i].mythread = i + threads * myproc;
	    tt_thread_data[i].peerthread = i + threads * (((myproc ^ 1) == numprocs) ? myproc : (myproc ^ 1));
        }
        test_createandjoin_pthreads(threads, &thread_main, tt_thread_data, sizeof(tt_thread_data[0]));
        test_free(tt_thread_data);
    }
#else
    { thread_data_t td;
      td.myproc = myproc;
      td.local_id = 0;
      td.mythread = myproc;
      td.peerthread = ((myproc ^ 1) == numprocs) ? myproc : (myproc ^ 1);

      thread_main(&td);
    }
#endif



    BARRIER();

    test_free(Aw);
    test_free(Bw);
    test_free(Cw);
    test_free(Dw);

    test_free_2D(Av);
    test_free_2D(Bv);
    test_free_2D(Cv);
    test_free_2D(Dv);

    test_free(R);

    MSG("done.");

    gasnet_exit(0);

    return 0;

}
Exemple #2
0
int main(int argc, char **argv)
{
    static int *A, *B, *C, *D, *E, *F, *G;
    gasnet_node_t myproc, i;
    int j;

    /* call startup */
    GASNET_Safe(gasnet_init(&argc, &argv));

    if (argc > 1) {
        iters = atoi(argv[1]);
    }
    if (iters < 1) {
        iters = 1000;
    }

#if GASNET_PAR
    if (argc > 2) {
        threads = atoi(argv[2]);
    }
    threads = test_thread_limit(threads);
    if (threads < 1) {
        printf("ERROR: Threads must be between 1 and %d\n", TEST_MAXTHREADS);
        exit(EXIT_FAILURE);
    }
#endif

    /* get SPMD info */
    myproc = gasnet_mynode();
    numprocs = gasnet_nodes();
    images = numprocs * threads;
    datasize = iters * (3 + 4 * images);

    GASNET_Safe(gasnet_attach(NULL, 0, TEST_SEGSZ_REQUEST, TEST_MINHEAPOFFSET));
    test_init("testcoll",0,"(iters) (threadcnt)");
    TEST_SET_WAITMODE(threads);
    if (argc > 3) test_usage();

    MSG0("Running coll test(s) with %d iterations.", iters);

    R = test_malloc(iters*sizeof(int));
    TEST_SRAND(1);

    /* Number if ints to store */

    /* Carve some variables out of the (aligned) segment: */
    Aw = test_malloc(iters * sizeof(int *));
    Bw = test_malloc(iters * sizeof(int *));
    Cw = test_malloc(iters * sizeof(int *));
    Dw = test_malloc(iters * sizeof(int *));
    Ew = test_malloc(iters * sizeof(int *));
    Fw = test_malloc(iters * sizeof(int *));
    Gw = test_malloc(iters * sizeof(int *));
    A = (int *)TEST_MYSEG();	/* int [1*iters] */
    B = A + 1*iters;		/* int [1*iters] */
    C = B + 1*iters;		/* int [N*iters] */
    D = C + images*iters;	/* int [N*iters] */
    E = D + images*iters;	/* int [1*iters] */
    F = E + 1*iters;		/* int [N*iters] */
    G = F + images*iters;	/* int [N*iters] */
    for (j = 0; j < iters; ++j) {
        Aw[j] = A + j;
        Bw[j] = B + j;
        Cw[j] = C + j*images;
        Dw[j] = D + j*images;
        Ew[j] = E + j;
        Fw[j] = F + j*images;
        Gw[j] = G + j*images;
    }

    /* The unaligned equivalents */
    Av = test_malloc_2D(iters, images * sizeof(int *));
    Bv = test_malloc_2D(iters, images * sizeof(int *));
    Cv = test_malloc_2D(iters, images * sizeof(int *));
    Dv = test_malloc_2D(iters, images * sizeof(int *));
    Ev = test_malloc_2D(iters, images * sizeof(int *));
    Fv = test_malloc_2D(iters, images * sizeof(int *));
    Gv = test_malloc_2D(iters, images * sizeof(int *));
    for (i = 0; i < images; ++i) {
        /* Using (TEST_SEG(n) + n) yields unaligned even when the segments are aligned.
           This is to help catch any case where addresses might have been misused that
           might go undetected if the addresses were aligned */
        A = (int *)TEST_SEG(i/threads) + (i/threads) + datasize*(i%threads);
        B = A + 1*iters;
        C = B + 1*iters;
        D = C + images*iters;
        E = D + images*iters;
        F = E + 1*iters;
        G = F + images*iters;
        for (j = 0; j < iters; ++j) {
            Av[j][i] = A + j;
            Bv[j][i] = B + j;
            Cv[j][i] = C + j*images;
            Dv[j][i] = D + j*images;
            Ev[j][i] = E + j;
            Fv[j][i] = F + j*images;
            Gv[j][i] = G + j*images;
        }
    }

    BARRIER();

#if GASNET_PAR
    MSG("Forking %d gasnet threads", threads);
    {
        int i;
        thread_data_t* tt_thread_data = test_malloc(threads*sizeof(thread_data_t));
        for (i = 0; i < threads; i++) {
            tt_thread_data[i].myproc = myproc;
            tt_thread_data[i].local_id = i;
            tt_thread_data[i].mythread = i + threads * myproc;
            tt_thread_data[i].peerthread = i + threads * (((myproc ^ 1) == numprocs) ? myproc : (myproc ^ 1));
        }
        test_createandjoin_pthreads(threads, &thread_main, tt_thread_data, sizeof(tt_thread_data[0]));
        test_free(tt_thread_data);
    }
#else
    {   thread_data_t td;
        td.myproc = myproc;
        td.local_id = 0;
        td.mythread = myproc;
        td.peerthread = ((myproc ^ 1) == numprocs) ? myproc : (myproc ^ 1);

        thread_main(&td);
    }
#endif



    BARRIER();

    test_free(Aw);
    test_free(Bw);
    test_free(Cw);
    test_free(Dw);

    test_free_2D(Av);
    test_free_2D(Bv);
    test_free_2D(Cv);
    test_free_2D(Dv);

    test_free(R);

    MSG("done.");

    gasnet_exit(0);

    return 0;

}