コード例 #1
0
void gasnete_amref_get_reqh_inner(gasnet_token_t token, 
  gasnet_handlerarg_t nbytes, void *dest, void *src, void *done) {
  gasneti_assert(nbytes <= gasnet_AMMaxMedium());
  GASNETI_SAFE(
    MEDIUM_REP(2,4,(token, gasneti_handleridx(gasnete_amref_get_reph),
                  src, nbytes, 
                  PACK(dest), PACK(done))));
}
コード例 #2
0
ファイル: grt.c プロジェクト: bocchino/ClusterSTM
void grt_init(int argc, char **argv) {

  pthread_t thread;

  /* Set up handler table */
  if (!entry_table) {
    entry_table = grt_entry_table;
    table_size = GRT_TABLE_SIZE;
  }

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

  /* get SPMD info */
  grt_id = gasnet_mynode();
  grt_num_procs = gasnet_nodes();
  gethostname(grt_proc_name, MAX_PROCESSOR_NAME);

  /* Attach to network */
  GASNET_Safe(gasnet_attach(entry_table, table_size,
			    GASNET_HEAP_SIZE, MINHEAPOFFSET));
  if (grt_id == 0) {
    printf("%s\n", argv[0]);
#ifdef GRT_WORD_32
      printf("We are on a 32-bit machine.\n");
#else
      printf("We are on a 64-bit machine.\n");
#endif
      printf("gasnet_AMMaxMedium()=%lu\n", gasnet_AMMaxMedium());
      printf("gasnet_AMMaxLongRequest()=%lu\n", gasnet_AMMaxLongRequest());
      printf("gasnet_AMMaxLongReply()=%lu\n", gasnet_AMMaxLongReply());
  }
  fflush(stdout);
  BARRIER();
  fflush(stdout);
  BARRIER();

  /* Get segment info */
  grt_seginfo = (gasnet_seginfo_t*) malloc(sizeof(gasnet_seginfo_t) *
					   grt_num_procs);
  GASNET_Safe(gasnet_getSegmentInfo(grt_seginfo, grt_num_procs));

  /* Initialize the heap for memory allocation */
  grt_heap_base = grt_addr(grt_id, 0);
  grt_heap = umalloc_makeheap(grt_heap_base,
			      grt_heap_size, UMALLOC_HEAP_GROWS_UP);  

  /* Spawn off a thread to handle remote handler requests */
  pthread_create(&thread, NULL, poll, NULL);

  /* Set up thread list */
  linkedlist_init(&thread_list, 0, 0);

  BARRIER();
}
コード例 #3
0
ファイル: testthreads.c プロジェクト: AlwaysTraining/chapel
void 
pong_medhandler(gasnet_token_t token, void *buf, size_t nbytes, 
		gasnet_handlerarg_t idx) 
{
	int	tid = tt_thread_data[idx].tid;

	PRINT_AM(("node=%2d> AMMedium Reply for tid=%d, (%d,%d)", 
			(int)gasnet_mynode(), tid, (int)gasnet_mynode(), (int)idx));
        assert(idx >= 0 && idx < threads_num);
        assert(tid >= 0 && tid < threads_num*gasnet_nodes());
        assert(nbytes <= gasnet_AMMaxMedium());
        assert((uintptr_t)buf+nbytes < (uintptr_t)TEST_SEG(gasnet_mynode()) ||
               (uintptr_t)buf >= (uintptr_t)TEST_SEG(gasnet_mynode()) + TEST_SEGSZ);
	tt_thread_data[idx].flag++;
}
コード例 #4
0
extern void gasnete_amref_get_nbi_bulk (void *dest, gasnet_node_t node, void *src, size_t nbytes GASNETE_THREAD_FARG) {
  gasnete_threaddata_t * const mythread = GASNETE_MYTHREAD;
  gasnete_iop_t * const op = mythread->current_iop;
  GASNETI_CHECKPSHM_GET(UNALIGNED,V);
  if (nbytes <= GASNETE_GETPUT_MEDIUM_LONG_THRESHOLD) {
    op->initiated_get_cnt++;
  
    GASNETI_SAFE(
      SHORT_REQ(4,7,(node, gasneti_handleridx(gasnete_amref_get_reqh), 
                   (gasnet_handlerarg_t)nbytes, PACK(dest), PACK(src), PACK_IOP_DONE(op,get))));
    return;
  } else {
    int chunksz;
    gasnet_handler_t reqhandler;
    uint8_t *psrc = src;
    uint8_t *pdest = dest;
    #if GASNETE_USE_LONG_GETS
      gasneti_memcheck(gasneti_seginfo);
      if (gasneti_in_segment(gasneti_mynode, dest, nbytes)) {
        chunksz = gasnet_AMMaxLongReply();
        reqhandler = gasneti_handleridx(gasnete_amref_getlong_reqh);
      }
      else 
    #endif
      { reqhandler = gasneti_handleridx(gasnete_amref_get_reqh);
        chunksz = gasnet_AMMaxMedium();
      }
    for (;;) {
      op->initiated_get_cnt++;
      if (nbytes > chunksz) {
        GASNETI_SAFE(
          SHORT_REQ(4,7,(node, reqhandler, 
                       (gasnet_handlerarg_t)chunksz, PACK(pdest), PACK(psrc), PACK_IOP_DONE(op,get))));
        nbytes -= chunksz;
        psrc += chunksz;
        pdest += chunksz;
      } else {
        GASNETI_SAFE(
          SHORT_REQ(4,7,(node, reqhandler, 
                       (gasnet_handlerarg_t)nbytes, PACK(pdest), PACK(psrc), PACK_IOP_DONE(op,get))));
        break;
      }
    }
    return;
  }
}
コード例 #5
0
ファイル: testthreads.c プロジェクト: AlwaysTraining/chapel
void 
ping_medhandler(gasnet_token_t token, void *buf, size_t nbytes, harg_t idx) 
{
	gasnet_node_t	node;
	gasnet_AMGetMsgSource(token, &node);

	PRINT_AM(("node=%2d> AMMedium Request for (%d,%d)", 
			(int)gasnet_mynode(), (int)node, (int)idx));
        assert(idx >= 0 && idx < threads_num);
        assert(node < gasnet_nodes());
        assert(nbytes <= gasnet_AMMaxMedium());
        assert((uintptr_t)buf+nbytes < (uintptr_t)TEST_SEG(gasnet_mynode()) ||
               (uintptr_t)buf >= (uintptr_t)TEST_SEG(gasnet_mynode()) + TEST_SEGSZ);
	GASNET_Safe(
		gasnet_AMReplyMedium1(token, hidx_pong_medhandler, 
			buf, nbytes, idx));
}
コード例 #6
0
ファイル: testcore1.c プロジェクト: deniskin82/chapel
int
main(int argc, char **argv)
{
	int	iters = 0;
	gasnet_handlerentry_t htable[] = {
		{ 201, chksum_reqh },
		{ 202, chksum_reph }
	};

	/* call startup */
        GASNET_Safe(gasnet_init(&argc, &argv));
        GASNET_Safe(gasnet_attach(htable, sizeof(htable)/sizeof(gasnet_handlerentry_t), TEST_SEGSZ_REQUEST, TEST_MINHEAPOFFSET));
	test_init("testcore1",0,"(iters)");

        assert(CHKSUM_TOTAL <= gasnet_AMMaxMedium());

	if (argc > 1) iters = atoi(argv[1]);
	if (!iters) iters = 1000;
        if (argc > 2) test_usage();
	

	/* get SPMD info */
	chksum_iters = iters;
	myproc = gasnet_mynode();
	numprocs = gasnet_nodes();
        /* Only allow even number for numprocs */
        if (numprocs % 2 != 0) {
          MSG("WARNING: This test requires an even number of nodes. Test skipped.\n");
          gasnet_exit(0); /* exit 0 to prevent false negatives in test harnesses for smp-conduit */
        }
	peerproc = (myproc % 2) ? myproc-1 : myproc+1;

	seginfo_table = (gasnet_seginfo_t *) test_malloc(sizeof(gasnet_seginfo_t) * numprocs);

	printf("%d> starting monoseed_init(%d)\n", myproc, iters);
	monoseed_init(iters);
	printf("%d> starting chksums_test(%d)\n", myproc, iters);
	chksum_test(iters);

	gasnet_exit(0);
	return(0);
}
コード例 #7
0
extern void gasnete_vis_init(void) {
  gasneti_assert(!gasnete_vis_isinit);
  gasnete_vis_isinit = 1;
  GASNETI_TRACE_PRINTF(C,("gasnete_vis_init()"));

  #define GASNETE_VIS_ENV_YN(varname, envname, enabler) do {                                                    \
    if (enabler) {                                                                                              \
      varname = gasneti_getenv_yesno_withdefault(#envname, enabler##_DEFAULT);                                  \
    } else if (!gasnet_mynode() && gasneti_getenv(#envname) && gasneti_getenv_yesno_withdefault(#envname, 0)) { \
      fprintf(stderr, "WARNING: %s is set in environment, but %s support is compiled out - setting ignored",    \
                      #envname, #enabler);                                                                      \
    }                                                                                                           \
  } while (0)
  #if GASNETE_USE_AMPIPELINE
  GASNETE_VIS_ENV_YN(gasnete_vis_use_ampipe,GASNET_VIS_AMPIPE, GASNETE_USE_AMPIPELINE);
  gasnete_vis_maxchunk = gasneti_getenv_int_withdefault("GASNET_VIS_MAXCHUNK", gasnet_AMMaxMedium()-2*sizeof(void*),1);
  #endif
  #if GASNETE_USE_REMOTECONTIG_GATHER_SCATTER
  GASNETE_VIS_ENV_YN(gasnete_vis_use_remotecontig,GASNET_VIS_REMOTECONTIG, GASNETE_USE_REMOTECONTIG_GATHER_SCATTER);
  #endif
}
コード例 #8
0
ファイル: testthreads.c プロジェクト: AlwaysTraining/chapel
void
test_ammedium(threaddata_t *tdata)
{
	int 	 	peer = RANDOM_PEER(tdata);
	int		node = tt_thread_map[peer];
	void		*laddr = tt_addr_map[tdata->tid];
	size_t	 	len;

	do {
		len = RANDOM_SIZE();
	} while (len > gasnet_AMMaxMedium());
		
	ACTION_PRINTF("tid=%3d> AMMediumRequest (sz=%7d) to tid=%3d", tdata->tid, (int)len, peer);
	tdata->flag = -1;
        gasnett_local_wmb();
	GASNET_Safe(gasnet_AMRequestMedium1(node, 
		    hidx_ping_medhandler, laddr, len, 
		    tdata->ltid));
	GASNET_BLOCKUNTIL(tdata->flag == 0);
	tdata->flag = -1;

	ACTION_PRINTF("tid=%3d> AMMediumRequest to tid=%3d complete.", tdata->tid, peer);
}
コード例 #9
0
ファイル: testam.c プロジェクト: bradcray/chapel
int main(int argc, char **argv) {
  int help=0;
  int arg=1;

  gasnet_handlerentry_t htable[] = { 
    { hidx_ping_shorthandler,  ping_shorthandler  },
    { hidx_pong_shorthandler,  pong_shorthandler  },
    { hidx_ping_medhandler,    ping_medhandler    },
    { hidx_pong_medhandler,    pong_medhandler    },
    { hidx_ping_longhandler,   ping_longhandler   },
    { hidx_pong_longhandler,   pong_longhandler   },

    { hidx_ping_shorthandler_flood,  ping_shorthandler_flood  },
    { hidx_pong_shorthandler_flood,  pong_shorthandler_flood  },
    { hidx_ping_medhandler_flood,    ping_medhandler_flood    },
    { hidx_pong_medhandler_flood,    pong_medhandler_flood    },
    { hidx_ping_longhandler_flood,   ping_longhandler_flood   },
    { hidx_pong_longhandler_flood,   pong_longhandler_flood   },

    { hidx_done_shorthandler,  done_shorthandler  }
  };

  GASNET_Safe(gasnet_init(&argc, &argv));

  mynode = gasnet_mynode();
  numnode = gasnet_nodes();

  arg = 1;
  while (argc > arg) {
    if (!strcmp(argv[arg], "-p")) {
#if GASNET_PAR
      pollers = test_thread_limit(atoi(argv[arg+1])+1)-1;
      arg += 2;
#else
      if (0 == mynode) {
        fprintf(stderr, "testam %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 (!strcmp(argv[arg], "-in")) {
      insegment = 1;
      ++arg;
    } else if (!strcmp(argv[arg], "-out")) {
      insegment = 0;
      ++arg;
    } else if (!strcmp(argv[arg], "-c")) {
      crossmachinemode = 1;
      ++arg;
    } else if (!strcmp(argv[arg], "-src-noop")) {
      src_mode = SRC_NOOP;
      ++arg;
    } else if (!strcmp(argv[arg], "-src-generate")) {
      src_mode = SRC_GENERATE;
      ++arg;
    } else if (!strcmp(argv[arg], "-src-memcpy")) {
      src_mode = SRC_MEMCPY;
      ++arg;
    } else if (argv[arg][0] == '-') {
      help = 1;
      ++arg;
    } else break;
  }

  if (argc > arg) { iters = atoi(argv[arg]); ++arg; }
  if (!iters) iters = 1000;
  if (argc > arg) { maxsz = atoi(argv[arg]); ++arg; }
  if (!maxsz) maxsz = 2*1024*1024;
  if (argc > arg) { TEST_SECTION_PARSE(argv[arg]); ++arg; }

  GASNET_Safe(gasnet_attach(htable, sizeof(htable)/sizeof(gasnet_handlerentry_t),
                            TEST_SEGSZ_REQUEST, TEST_MINHEAPOFFSET));
#if GASNET_PAR
  #define PAR_USAGE \
               "  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 PAR_USAGE ""
#endif
  test_init("testam", 1, "[options] (iters) (maxsz) (test_sections)\n"
               "  The '-in' or '-out' option selects whether the requestor's\n"
               "    buffer is in the GASNet segment or not (default is 'in').\n"
               PAR_USAGE
               "  The '-src-*' options select treatment of the payload buffer used for\n"
               "    Medium and Long AMs, as follows:\n"
               "      -src-noop:      no per-operation initialization (default)\n"
               "      -src-generate:  initialized (w/o memory reads) on each AM injection\n"
               "      -src-memcpy:    initialized using memcpy() on each AM injection\n"
               "  The -c option enables cross-machine pairing (default is nearest neighbor).\n");
  if (help || argc > arg) test_usage();

  TEST_PRINT_CONDUITINFO();

  if (insegment) {
    myseg = TEST_MYSEG();
  } else {
    char *space = test_malloc(alignup(maxsz,PAGESZ) + PAGESZ);
    myseg = alignup_ptr(space, PAGESZ);
  }

  maxmed = MIN(maxsz, gasnet_AMMaxMedium());
  maxlongreq = MIN(maxsz, gasnet_AMMaxLongRequest());
  maxlongrep = MIN(maxsz, gasnet_AMMaxLongReply());

  if (src_mode == SRC_MEMCPY) {
    zero_buffer = test_calloc(maxsz, 1);
  }

  if (crossmachinemode) {
    if ((numnode%2) && (mynode == numnode-1)) {
      sender = 1;
      peer = mynode;
    } else {
      gasnet_node_t half = numnode / 2;
      sender = (mynode < half);
      peer = sender ? (mynode + half) : (mynode - half);
    }
  } else {
    peer = mynode ^ 1;
    sender = mynode % 2 == 0;
    if (peer == numnode) {
      peer = mynode;
    }
  }

  recvr = !sender || (peer == mynode);

  // Long Request and Reply (distinct for loopback)
  reply_addr = TEST_SEG(peer);
  request_addr = (peer == mynode) ? (void*)((uintptr_t)reply_addr + alignup(maxsz,SIZEOF_GASNET_REGISTER_VALUE_T))
                                  : reply_addr;

  BARRIER();

#if GASNET_PAR
  #define PAR_FMT "  %i extra recvr polling threads\n"
  #define PAR_ARG ,pollers
#else
  #define PAR_FMT /*empty*/
  #define PAR_ARG /*empty*/
#endif
  if (mynode == 0) {
      printf("Running %i iterations of %s AM performance with:\n"
             "  local addresses %sside the segment%s\n"
             "  %s\n"
             PAR_FMT
             "  ...\n",
             iters,
             (crossmachinemode ? "cross-machine ": ""),
             (insegment ? "in" : "out"),
             (insegment ? " (default)" : ""),
             ((src_mode == SRC_NOOP)     ? "no payload initialization (default)"
             :(src_mode == SRC_GENERATE) ? "payload initialized by computation"
                                         : "payload initialized using memcpy()")
             PAR_ARG
            );
      printf("   Msg Sz  Description                             Total time   Avg. time   Bandwidth\n"
             "   ------  -----------                             ----------   ---------   ---------\n");
      fflush(stdout);
  }
#if GASNET_PAR
  TEST_SET_WAITMODE(pollers+1);
  if (pollers)
    test_createandjoin_pthreads(pollers+1,doAll,NULL,0);
  else
#endif
    doAll(NULL);

  MSG("done.");

  gasnet_exit(0);
  return 0;
}
コード例 #10
0
ファイル: testcore2.c プロジェクト: AbheekG/chapel
void *doit(void *id) {
  gasnett_threadkey_set(mythread,id); 
  if ((uintptr_t)id != 0) { /* additional threads polling, to encourage handler concurrency */
    while (!done) {
      gasnet_AMPoll();
      gasnett_sched_yield();
    }
    return 0;
  } 

  MSG0("Running %sAM%s%s%s%s correctness test %s%swith %i iterations, max_payload=%i, depth=%i...",
#if GASNET_PAR
    (domultith?"multi-threaded ":"single-threaded "),
#else
    "",
#endif
    (amopt?(domed?" Medium":""):""),(amopt?(dolong?" Long":""):""),(amopt?(dolongasync?" LongAsync":""):""),
    ((doinseg^dooutseg)?(doinseg?" in-segment":" out-of-segment"):""),
    (dosizesync?"":"loosely-synced "),
    (doprime?"with priming ":""),
    iters,max_payload,depth);

  BARRIER();
  if (doprime) { /* issue some initial puts that cover the Long regions, to try and trigger dynamic pinning */
    int chunkidx;
    for (chunkidx = 0; chunkidx < depth; chunkidx++) {
      /* AMRequestLong primer */
      gasnet_put(peerproc, peerreqseg+chunkidx*max_payload, privateseg+chunkidx*max_payload, max_payload);
      gasnet_put(peerproc, peerreqseg+chunkidx*max_payload, localseg+chunkidx*max_payload, max_payload);
      /* AMRequestLongAsync primer */
      gasnet_put(peerproc, peerreqseg+(depth+chunkidx)*max_payload, privateseg+chunkidx*max_payload, max_payload);
      gasnet_put(peerproc, peerreqseg+(depth+chunkidx)*max_payload, localseg+chunkidx*max_payload, max_payload);
      /* AMReplyLong primer */
      gasnet_put(peerproc, peerrepseg+chunkidx*max_payload, myseg+chunkidx*max_payload, max_payload);
      gasnet_put(peerproc, peerrepseg+chunkidx*max_payload, longreplysrc+chunkidx*max_payload, max_payload);
      /* AMReplyLongAsync primer */
      gasnet_put(peerproc, peerrepseg+(depth+chunkidx)*max_payload, myseg+(depth+chunkidx)*max_payload, max_payload);
      gasnet_put(peerproc, peerrepseg+(depth+chunkidx)*max_payload, alongreplysrc+chunkidx*max_payload, max_payload);
    }
    BARRIER();
  }

  { int sz,iter,savesz = 1;
    int max1 = gasnet_AMMaxMedium(), max2 = maxlong;
    if (maxlong < gasnet_AMMaxMedium()) { max1 = maxlong; max2 = gasnet_AMMaxMedium(); }
    assert_always(max1 <= max2);

    for (sz = 1; sz <= max_payload; ) {
      if (dosizesync) BARRIER(); /* optional barrier, to synchronize tests at each payload size across nodes */
      
      MSG0("payload = %i",sz);

      for (iter = 0; iter < iters; iter++) {
        int chunkidx;
        uint8_t *srcseg = ITERSEG(iter);

        /* initialize local seg to known values */
        for (chunkidx = 0; chunkidx < depth; chunkidx++) {
          init_chunk(srcseg,sz,iter,chunkidx);
        }
        if (domed && sz <= gasnet_AMMaxMedium()) { /* test Medium AMs */
          gasnett_atomic_set(&pong_recvd,0,0);
          for (chunkidx = 0; chunkidx < depth; chunkidx++) {
            GASNET_Safe(gasnet_AMRequestMedium2(peerproc, hidx_ping_medhandler, srcseg+chunkidx*sz, sz,
                                    iter, chunkidx));
          }
          /* wait for completion */
          GASNET_BLOCKUNTIL(gasnett_atomic_read(&pong_recvd,0) == depth);
        }

        if (sz <= maxlong) { 
         if (dolong) { /* test Long AMs */
          gasnett_atomic_set(&pong_recvd,0,0);
          for (chunkidx = 0; chunkidx < depth; chunkidx++) {
            GASNET_Safe(gasnet_AMRequestLong2(peerproc, hidx_ping_longhandler, srcseg+chunkidx*sz, sz,
                                  peerreqseg+chunkidx*sz, iter, chunkidx));
          }
          /* wait for completion */
          GASNET_BLOCKUNTIL(gasnett_atomic_read(&pong_recvd,0) == depth);
         }

         if (dolongasync) {  /* test AsyncLong AMs */
          gasnett_atomic_set(&pong_recvd,0,0);
          for (chunkidx = 0; chunkidx < depth; chunkidx++) {
            GASNET_Safe(gasnet_AMRequestLongAsync2(peerproc, hidx_ping_alonghandler, srcseg+chunkidx*sz, sz,
                                  peerreqseg+(depth+chunkidx)*sz, iter, chunkidx));
          }
          /* wait for completion */
          GASNET_BLOCKUNTIL(gasnett_atomic_read(&pong_recvd,0) == depth);
         }
        }
      }

      /* double sz each time, but make sure to also exactly hit MaxMedium, MaxLong and max payload */
      if (sz < max1 && savesz * 2 > max1) sz = max1;
      else if (sz < max2 && savesz * 2 > max2) sz = max2;
      else if (sz < max_payload && savesz * 2 > max_payload) sz = max_payload;
      else { sz = savesz * 2; savesz = sz; }
    }
  }

  BARRIER();
  done = 1;

  return(0);
}
コード例 #11
0
ファイル: testcore2.c プロジェクト: AbheekG/chapel
int main(int argc, char **argv) {
  int arg = 1, help = 0;
  gasnet_handlerentry_t htable[] = {
    { hidx_ping_medhandler,    ping_medhandler    },
    { hidx_pong_medhandler,    pong_medhandler    },
    { hidx_ping_longhandler,   ping_longhandler   },
    { hidx_pong_longhandler,   pong_longhandler   },
    { hidx_ping_alonghandler,  ping_alonghandler  },
  };

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

  #define AMOPT() if (!amopt) { amopt = 1; domed = 0; dolong = 0; dolongasync = 0; }
  while (argc > arg) {
    if (!strcmp(argv[arg], "-p")) {
      doprime = 1;
      ++arg;
    } else if (!strcmp(argv[arg], "-u")) {
      dosizesync = 0;
      ++arg;
    } else if (!strcmp(argv[arg], "-s")) {
      domultith = 0;
      ++arg;
    } else if (!strcmp(argv[arg], "-n")) {
      allowretry = 0;
      ++arg;
    } else if (!strcmp(argv[arg], "-in")) {
      doinseg = 1; dooutseg = 0;
      ++arg;
    } else if (!strcmp(argv[arg], "-out")) {
      doinseg = 0; dooutseg = 1;
      ++arg;
    } else if (!strcmp(argv[arg], "-m")) {
      AMOPT();
      domed = 1; 
      ++arg;
    } else if (!strcmp(argv[arg], "-l")) {
      AMOPT();
      dolong = 1;
      ++arg;
    } else if (!strcmp(argv[arg], "-a")) {
      AMOPT();
      dolongasync = 1;
      ++arg;
    } else if (argv[arg][0] == '-') {
      help = 1;
      ++arg;
    } else break;
  }

  if (argc > arg) { iters = atoi(argv[arg]); arg++; }
  if (!iters) iters = 10;
  if (argc > arg) { max_payload = atoi(argv[arg]); arg++; }
  if (!max_payload) max_payload = 1024*1024;
  if (argc > arg) { depth = atoi(argv[arg]); arg++; }
  if (!depth) depth = 16;

  /* round down to largest payload AM allows */
  maxlong = MIN(gasnet_AMMaxLongRequest(),gasnet_AMMaxLongReply());
  max_payload = MIN(max_payload,MAX(gasnet_AMMaxMedium(),maxlong));

  GASNET_Safe(gasnet_attach(htable, sizeof(htable)/sizeof(gasnet_handlerentry_t), TEST_SEGSZ_REQUEST, TEST_MINHEAPOFFSET));
  test_init("testcore2",0,"[options] (iters) (max_payload) (depth)\n"
                 "  -m   test AMMedium    (defaults to all types)\n"
                 "  -l   test AMLong      (defaults to all types)\n"
                 "  -a   test AMLongAsync (defaults to all types)\n"
                 "  -p   prime the AMLong transfer areas with puts, to encourage pinning\n"
                 "  -u   loosen sychronization to allow diff payload sizes to be in flight at once\n"
                 "  -s   single-threaded PAR mode (default is to start a polling thread in PAR mode)\n"
                 "  -n   no retry on failure\n"
                 "  -in/-out use only in- or out-of-segment sources for AMLong(Async) (default is both)\n"
                 );
  if (help || argc > arg) test_usage();

  TEST_PRINT_CONDUITINFO();

  /* get SPMD info */
  myproc = gasnet_mynode();
  numprocs = gasnet_nodes();

  peerproc = myproc ^ 1;
  if (peerproc == gasnet_nodes()) {
    /* w/ odd # of nodes, last one talks to self */
    peerproc = myproc;
  }
  myseg = TEST_MYSEG();
  peerreqseg = TEST_SEG(peerproc);
  peerrepseg = peerreqseg+max_payload*depth*2;
  localseg = myseg + max_payload*depth*4;
  assert_always(TEST_SEGSZ >= max_payload*depth*5);
  privateseg = test_malloc(max_payload*depth*3); /* out-of-seg request src, long reply src, along reply src  */
  longreplysrc = privateseg+max_payload*depth;
  alongreplysrc = privateseg+max_payload*depth*2;

  #ifdef GASNET_PAR
    if (domultith) test_createandjoin_pthreads(2,doit,NULL,0);
    else
  #endif
      doit(0);

  BARRIER();
  test_free(privateseg);
  MSG("done. (detected %i errs)", test_errs);
  gasnet_exit(test_errs > 0 ? 1 : 0);
  return 0;
}
コード例 #12
0
ファイル: testthreads.c プロジェクト: AlwaysTraining/chapel
int
main(int argc, char **argv)
{
	int		i;
        const char *getopt_str;
        int opt_p=0, opt_g=0, opt_a=0, opt_m=0;

        #if TEST_MPI
          init_test_mpi(&argc, &argv);
          getopt_str = "pgamlvtdi:";
        #else
          getopt_str = "pgalvtdi:";
        #endif

	GASNET_Safe(gasnet_init(&argc, &argv));
    	GASNET_Safe(gasnet_attach(htable, HANDLER_TABLE_SIZE,
		    TEST_SEGSZ_REQUEST, TEST_MINHEAPOFFSET));

        #if TEST_MPI
          #define TEST_MPI_USAGE  "  -m  use MPI calls                              \n"
        #else
          #define TEST_MPI_USAGE  ""
        #endif
        #if GASNET_PAR
          #define TEST_THREAD_USAGE " [<threads_per_node>]\n\n" \
	    "<threads_per_node> must be between 1 and "_STRINGIFY(TEST_MAXTHREADS)"       \n"
        #else
          #define TEST_THREAD_USAGE  "\n\n"
        #endif
	test_init("testthreads",0, "[ -pgalvtd ] [ -i <iters> ]"
            TEST_THREAD_USAGE
	    "no options means run all tests with "_STRINGIFY(DEFAULT_ITERS)" iterations\n"
	    "options:                                      \n"
	    "  -p  use puts                                   \n"
	    "  -g  use gets                                   \n"
	    "  -a  use Active Messages                        \n"
	    "  -l  use local Active Messages                  \n"
            TEST_MPI_USAGE
	    "  -v  output information about actions taken     \n"
	    "  -t  include AM handler actions with -v         \n"
	    "  -d  dynamic thread creation stress test        \n"
	    "  -i <iters> use <iters> iterations per thread   \n");

	while ((i = getopt (argc, argv, getopt_str)) != EOF) {
          switch (i) {
		case 'p': opt_p = 1; break;
		case 'g': opt_g = 1; break;
		case 'a': opt_a = 1; break;
                case 'm': opt_m = 1; break;
		case 'l': AM_loopback = 1; break;
		case 'i': iters = atoi(optarg); break;
                case 'v': verbose = 1; break;
                case 't': amtrace = 1; break;
                case 'd': threadstress = 1; break;
		default: test_usage();
          }
	}

        if (opt_p) test_functions[functions_num++] = test_put;
        if (opt_g) test_functions[functions_num++] = test_get;
        if (opt_a) {
          test_functions[functions_num++] = test_amshort;
          test_functions[functions_num++] = test_ammedium;
          test_functions[functions_num++] = test_amlong;
        }
        #if TEST_MPI
          if (opt_m) test_functions[functions_num++] = test_mpi;
        #endif
        if (amtrace) verbose = 1;

	/* Assume all test functions if no option is passed */
	if (functions_num  == 0) {
		MSG("running all functions!");
		
		memcpy(test_functions, test_functions_all, 
				sizeof(test_functions_all));
		functions_num = NUM_FUNCTIONS;
	}

	argc -= optind;

	if (argc > 1) test_usage();
	else if (argc == 1) {
		argv += optind;
		threads_num = atoi(argv[0]);
	}

	if (threads_num > TEST_MAXTHREADS || threads_num < 1) {
		printf("ERROR: Threads must be between 1 and %i\n",TEST_MAXTHREADS);
		exit(EXIT_FAILURE);
	}

        /* limit sizes to a reasonable size */
        #define LIMIT(sz) MIN(sz,4194304)
        { int sz = 0;
          sizes[sz++] = LIMIT(gasnet_AMMaxMedium()-1);
          sizes[sz++] = LIMIT(gasnet_AMMaxMedium());
          sizes[sz++] = LIMIT(gasnet_AMMaxMedium()+1);
          sizes[sz++] = LIMIT(gasnet_AMMaxLongRequest()-1);
          sizes[sz++] = LIMIT(gasnet_AMMaxLongRequest());
          sizes[sz++] = LIMIT(gasnet_AMMaxLongRequest()+1);
          sizes[sz++] = LIMIT(gasnet_AMMaxLongReply()-1);
          sizes[sz++] = LIMIT(gasnet_AMMaxLongReply());
          sizes[sz++] = LIMIT(gasnet_AMMaxLongReply()+1);
          assert(sizes[sz] == 0);
        }

	alloc_thread_data(threads_num);
        #if TEST_MPI
          attach_test_mpi();
        #endif

        #ifdef GASNET_PAR
          if (threadstress) {
            int spawniters = MAX(1,iters/threads_num);
            int i;
            MSG("Dynamic thread creation stress test, %d gasnet threads, (%d at a time)", spawniters*threads_num, threads_num);
            iters = 10; /* enough iters to ensure we get thread registration */
            for (i = 0; i < spawniters; i++) {
              test_createandjoin_pthreads(threads_num, &threadmain, tt_thread_data, sizeof(threaddata_t));
              TEST_PROGRESS_BAR(i, spawniters);
            }
          } else {
            MSG("Forking %d gasnet threads and running %d iterations", threads_num, iters);
            test_createandjoin_pthreads(threads_num, &threadmain, tt_thread_data, sizeof(threaddata_t));
          }
        #else /* for testmpi-seq and -parsync */
         #ifdef GASNET_SEQ
  	  MSG("Running with 1 thread/node for GASNET_SEQ mode");
         #else
  	  MSG("Running with 1 thread/node for GASNET_PARSYNC mode");
         #endif
          threadmain(tt_thread_data);
        #endif

        BARRIER();

	free_thread_data();

	MSG("Tests complete");

        BARRIER();

	gasnet_exit(0);

	return 0;
}
コード例 #13
0
ファイル: testam.c プロジェクト: AlwaysTraining/chapel
int main(int argc, char **argv) {
  int help=0;
  int arg=1;

  gasnet_handlerentry_t htable[] = { 
    { hidx_ping_shorthandler,  ping_shorthandler  },
    { hidx_pong_shorthandler,  pong_shorthandler  },
    { hidx_ping_medhandler,    ping_medhandler    },
    { hidx_pong_medhandler,    pong_medhandler    },
    { hidx_ping_longhandler,   ping_longhandler   },
    { hidx_pong_longhandler,   pong_longhandler   },

    { hidx_ping_shorthandler_flood,  ping_shorthandler_flood  },
    { hidx_pong_shorthandler_flood,  pong_shorthandler_flood  },
    { hidx_ping_medhandler_flood,    ping_medhandler_flood    },
    { hidx_pong_medhandler_flood,    pong_medhandler_flood    },
    { hidx_ping_longhandler_flood,   ping_longhandler_flood   },
    { hidx_pong_longhandler_flood,   pong_longhandler_flood   },

    { hidx_done_shorthandler,  done_shorthandler  }
  };

  GASNET_Safe(gasnet_init(&argc, &argv));

  mynode = gasnet_mynode();
  numnode = gasnet_nodes();

  arg = 1;
  while (argc > arg) {
    if (!strcmp(argv[arg], "-p")) {
#if GASNET_PAR
      pollers = atoi(argv[arg+1]);
      arg += 2;
#else
      if (0 == mynode) {
        fprintf(stderr, "testam %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 (!strcmp(argv[arg], "-in")) {
      insegment = 1;
      ++arg;
    } else if (!strcmp(argv[arg], "-out")) {
      insegment = 0;
      ++arg;
    } else if (!strcmp(argv[arg], "-c")) {
      crossmachinemode = 1;
      ++arg;
    } else if (argv[arg][0] == '-') {
      help = 1;
      ++arg;
    } else break;
  }

  if (argc > arg) { iters = atoi(argv[arg]); ++arg; }
  if (!iters) iters = 1000;
  if (argc > arg) { maxsz = atoi(argv[arg]); ++arg; }
  if (!maxsz) maxsz = 2*1024*1024;
  if (argc > arg) { TEST_SECTION_PARSE(argv[arg]); ++arg; }

  GASNET_Safe(gasnet_attach(htable, sizeof(htable)/sizeof(gasnet_handlerentry_t),
                            TEST_SEGSZ_REQUEST, TEST_MINHEAPOFFSET));
#if GASNET_PAR
  test_init("testam", 1, "[options] (iters) (maxsz) (test_sections)\n"
               "  The '-in' or '-out' option selects whether the requestor's\n"
               "    buffer is in the GASNet segment or not (default is 'in').\n"
               "  The -p option gives the number of polling threads, specified as\n"
               "    a non-negative integer argument (default is no polling threads).\n"
               "  The -c option enables cross-machine pairing (default is nearest neighbor).\n");
#else
  test_init("testam", 1, "[options] (iters) (maxsz) (test_sections)\n"
               "  The '-in' or '-out' option selects whether the requestor's\n"
               "    buffer is in the GASNet segment or not (default is 'in').\n"
               "  The -c option enables cross-machine pairing (default is nearest neighbor).\n");
#endif
  if (help || argc > arg) test_usage();

  TEST_PRINT_CONDUITINFO();

  if (insegment) {
    myseg = TEST_MYSEG();
  } else {
    char *space = test_malloc(alignup(maxsz,PAGESZ) + PAGESZ);
    myseg = alignup_ptr(space, PAGESZ);
  }

  maxmed = MIN(maxsz, gasnet_AMMaxMedium());
  maxlongreq = MIN(maxsz, gasnet_AMMaxLongRequest());
  maxlongrep = MIN(maxsz, gasnet_AMMaxLongReply());

  if (crossmachinemode) {
    if ((numnode%2) && (mynode == numnode-1)) {
      sender = 1;
      peer = mynode;
    } else {
      gasnet_node_t half = numnode / 2;
      sender = (mynode < half);
      peer = sender ? (mynode + half) : (mynode - half);
    }
  } else {
    peer = mynode ^ 1;
    sender = mynode % 2 == 0;
    if (peer == numnode) {
      peer = mynode;
    }
  }

  recvr = !sender || (peer == mynode);

  peerseg = TEST_SEG(peer);

  BARRIER();

  if (mynode == 0) {
      printf("Running %sAM performance test with %i iterations"
#if GASNET_PAR
             " and %i extra recvr polling threads"
#endif
             "...\n",
             (crossmachinemode ? "cross-machine ": ""),
             iters
#if GASNET_PAR
             ,pollers
#endif
            );
      printf("   Msg Sz  Description                             Total time   Avg. time   Bandwidth\n"
             "   ------  -----------                             ----------   ---------   ---------\n");
      fflush(stdout);
  }
#if GASNET_PAR
  if (pollers)
    test_createandjoin_pthreads(pollers+1,doAll,NULL,0);
  else
#endif
    doAll(NULL);

  MSG("done.");

  gasnet_exit(0);
  return 0;
}