static int test_item5(void) { int rc = TC_PASS; TYPE_VALUE* shmem_addr = NULL; TYPE_VALUE* send_addr = NULL; TYPE_VALUE my_value = 0; TYPE_VALUE peer_value = 0; TYPE_VALUE expect_value = 0; int num_proc = 0; int my_proc = 0; int root_proc = 0; num_proc = _num_pes(); my_proc = _my_pe(); shmem_addr = (TYPE_VALUE*)shmalloc(sizeof(*shmem_addr) * __max_buffer_size); send_addr = (TYPE_VALUE*)shmalloc(sizeof(*send_addr) * __max_buffer_size); if (shmem_addr && send_addr) { TYPE_VALUE value = DEFAULT_VALUE; int i = 0; int j = 0; long cur_buf_size = 0; for (i = 0; (i < __cycle_count) && (rc == TC_PASS); i++) { cur_buf_size = sys_max(1, (i + 1) * __max_buffer_size / __cycle_count); /* Set my value */ my_value = DEFAULT_VALUE; fill_buffer((void *)shmem_addr, cur_buf_size, (void *)&my_value, sizeof(my_value)); /* Give some time to all PE for setting their values */ shmem_barrier_all(); /* Define peer and it value */ peer_value = (i * (MAX_VALUE / __cycle_count)); fill_buffer((void *)send_addr, cur_buf_size, (void *)&peer_value, sizeof(peer_value)); /* Set root */ root_proc = 0; /* Define expected value */ expect_value = (((my_proc % 2) == 0) && (my_proc != root_proc) ? peer_value : DEFAULT_VALUE); /* This guarantees that PE set initial value before peer change one */ for ( j = 0; j < _SHMEM_COLLECT_SYNC_SIZE; j++ ) { pSync[j] = _SHMEM_SYNC_VALUE; } shmem_barrier_all(); /* Put value to peer */ if ((my_proc % 2) == 0) { FUNC_VALUE(shmem_addr, send_addr, cur_buf_size, root_proc, 0, 1, ((num_proc / 2) + (num_proc % 2)), pSync); } /* Get value put by peer: * These routines start the remote transfer and may return before the data * is delivered to the remote PE */ shmem_barrier_all(); { int wait = WAIT_COUNT; while (wait--) { value = *shmem_addr; if (expect_value == value) break; sleep(1); } } rc = (!compare_buffer_with_const(shmem_addr, cur_buf_size, &expect_value, sizeof(expect_value)) ? TC_PASS : TC_FAIL); log_debug(OSH_TC, "my#%d root(#%d:%lld) expected = %lld actual = %lld buffer size = %lld\n", my_proc, root_proc, (INT64_TYPE)peer_value, (INT64_TYPE)expect_value, (INT64_TYPE)value, (INT64_TYPE)cur_buf_size); if (rc) { TYPE_VALUE* check_addr = shmem_addr; int odd_index = compare_buffer_with_const(check_addr, cur_buf_size, &expect_value, sizeof(expect_value)); int show_index = (odd_index > 1 ? odd_index - 2 : 0); int show_size = sizeof(*check_addr) * sys_min(3, cur_buf_size - show_index); log_debug(OSH_TC, "index of incorrect value: 0x%08X (%d)\n", odd_index - 1, odd_index - 1); log_debug(OSH_TC, "buffer interval: 0x%08X - 0x%08X\n", show_index, show_index + show_size); show_buffer(check_addr + show_index, show_size); } } } else { rc = TC_SETUP_FAIL; } if (send_addr) { shfree(send_addr); } if (shmem_addr) { shfree(shmem_addr); } return rc; }
static int test_item7(void) { int rc = TC_PASS; static TYPE_VALUE shmem_addr[MAX_BUFFER_SIZE * 2]; static TYPE_VALUE send_addr[MAX_BUFFER_SIZE * 2]; TYPE_VALUE my_value = 0; TYPE_VALUE peer_value = 0; TYPE_VALUE expect_value = 0; int num_proc = 0; int my_proc = 0; int root_proc = 0; long* pSyncMult = NULL; int pSyncNum = 2; num_proc = _num_pes(); my_proc = _my_pe(); pSyncMult = shmalloc(sizeof(*pSyncMult) * pSyncNum * _SHMEM_COLLECT_SYNC_SIZE); if (!pSyncMult) { rc = TC_SETUP_FAIL; } if (rc == TC_PASS) { int i = 0; int j = 0; for ( j = 0; j < pSyncNum * _SHMEM_COLLECT_SYNC_SIZE; j++ ) { pSyncMult[j] = _SHMEM_SYNC_VALUE; } /* Give some time to all PE for setting their values */ shmem_barrier_all(); /* Set root */ root_proc = 0; my_value = DEFAULT_VALUE; peer_value = MAX_VALUE; expect_value = (my_proc == root_proc ? DEFAULT_VALUE : peer_value); fill_buffer((void *)send_addr, MAX_BUFFER_SIZE * 2, (void *)&peer_value, sizeof(peer_value)); fill_buffer((void *)shmem_addr, MAX_BUFFER_SIZE * 2, (void *)&my_value, sizeof(my_value)); shmem_barrier_all(); for (i = 0; (i < __cycle_count) && (rc == TC_PASS); i++) { /* Put value to peer */ FUNC_VALUE(shmem_addr + (i % 2) * MAX_BUFFER_SIZE, send_addr + (i % 2) * MAX_BUFFER_SIZE, MAX_BUFFER_SIZE, root_proc, 0, 0, num_proc, pSyncMult + (i % pSyncNum) * _SHMEM_COLLECT_SYNC_SIZE); rc = (!compare_buffer_with_const(shmem_addr + (i % 2) * MAX_BUFFER_SIZE, MAX_BUFFER_SIZE, &expect_value, sizeof(expect_value)) ? TC_PASS : TC_FAIL); log_debug(OSH_TC, "my#%d root(#%d:%lld) expected = %lld actual = %lld buffer size = %lld\n", my_proc, root_proc, (INT64_TYPE)peer_value, (INT64_TYPE)expect_value, (INT64_TYPE)(*shmem_addr), (INT64_TYPE)MAX_BUFFER_SIZE); if (rc) { TYPE_VALUE* check_addr = shmem_addr + (i % 2) * MAX_BUFFER_SIZE; int odd_index = compare_buffer_with_const(check_addr, MAX_BUFFER_SIZE, &expect_value, sizeof(expect_value)); int show_index = (odd_index > 1 ? odd_index - 2 : 0); int show_size = sizeof(*check_addr) * sys_min(3, MAX_BUFFER_SIZE - show_index); log_debug(OSH_TC, "index of incorrect value: 0x%08X (%d)\n", odd_index - 1, odd_index - 1); log_debug(OSH_TC, "buffer interval: 0x%08X - 0x%08X\n", show_index, show_index + show_size); show_buffer(check_addr + show_index, show_size); } fill_buffer((void *)(send_addr + (i % 2) * MAX_BUFFER_SIZE), MAX_BUFFER_SIZE, (void *)&peer_value, sizeof(peer_value)); fill_buffer((void *)(shmem_addr + (i % 2) * MAX_BUFFER_SIZE ), MAX_BUFFER_SIZE, (void *)&my_value, sizeof(my_value)); } } if (pSyncMult) { shfree(pSyncMult); } return rc; }
static int test_item4(void) { int rc = TC_PASS; TYPE_VALUE* shmem_addr = NULL; TYPE_VALUE* recv_addr = NULL; TYPE_VALUE my_value = 0; TYPE_VALUE peer_value = 0; TYPE_VALUE expect_value = 0; int num_proc = 0; int my_proc = 0; int peer_proc = 0; num_proc = _num_pes(); my_proc = _my_pe(); shmem_addr = (TYPE_VALUE*)shmalloc(sizeof(*shmem_addr) * __max_buffer_size); recv_addr = (TYPE_VALUE*)sys_malloc(sizeof(*recv_addr) * __max_buffer_size); if (shmem_addr && recv_addr) { INT64_TYPE i = 0; long cur_buf_size = 0; my_value = 0; for (i = 0; (i < __cycle_count) && (rc == TC_PASS); i++) { /* Set my value */ my_value = (my_proc % 2 ? 1 : -1) * (i * (MAX_VALUE / __cycle_count)); cur_buf_size = sys_max(1, (i + 1) * __max_buffer_size / __cycle_count); fill_buffer((void *)shmem_addr, cur_buf_size, (void *)&my_value, sizeof(my_value)); /* Give some time to all PE for setting their values */ shmem_barrier_all(); /* Define peer and it value */ peer_proc = (my_proc + 1) % num_proc; peer_value = (peer_proc % 2 ? 1 : -1) * (i * (MAX_VALUE / __cycle_count)); /* Define expected value */ expect_value = peer_value; /* Get value from peer */ FUNC_VALUE(recv_addr, shmem_addr, cur_buf_size, peer_proc); rc = (!compare_buffer_with_const(recv_addr, cur_buf_size, &expect_value, sizeof(expect_value)) ? TC_PASS : TC_FAIL); log_debug(OSH_TC, "my(#%d:%lld) peer(#%d:%lld) expected = %lld buffer size = %lld\n", my_proc, (INT64_TYPE)my_value, peer_proc, (INT64_TYPE)peer_value, (INT64_TYPE)expect_value, (INT64_TYPE)cur_buf_size); if (rc) { TYPE_VALUE* check_addr = recv_addr; int odd_index = compare_buffer_with_const(check_addr, cur_buf_size, &expect_value, sizeof(expect_value)); int show_index = (odd_index > 1 ? odd_index - 2 : 0); int show_size = sizeof(*check_addr) * sys_min(3, cur_buf_size - odd_index - 1); log_debug(OSH_TC, "index of incorrect value: 0x%08X (%d)\n", odd_index - 1, odd_index - 1); log_debug(OSH_TC, "buffer interval: 0x%08X - 0x%08X\n", show_index, show_index + show_size); show_buffer(check_addr + show_index, show_size); } shmem_barrier_all(); } } else { rc = TC_SETUP_FAIL; } if (recv_addr) { sys_free(recv_addr); } if (shmem_addr) { shfree(shmem_addr); } return rc; }
static int test_item4(void) { int rc = TC_PASS; TYPE_VALUE* shmem_addr = NULL; TYPE_VALUE* send_addr = NULL; TYPE_VALUE my_value = 0; TYPE_VALUE peer_value = 0; TYPE_VALUE expect_value = 0; int num_proc = 0; int my_proc = 0; int root_proc = 0; num_proc = _num_pes(); my_proc = _my_pe(); shmem_addr = shmalloc(sizeof(*shmem_addr)); send_addr = shmalloc(sizeof(*send_addr)); if (shmem_addr && send_addr) { TYPE_VALUE value = DEFAULT_VALUE; int j = 0; /* Set my value */ my_value = DEFAULT_VALUE; *shmem_addr = my_value; /* Define peer and it value */ peer_value = BASE_VALUE; *send_addr = peer_value; /* Set root */ root_proc = 0; /* Define expected value */ expect_value = (((my_proc % 2) == 0) && (my_proc != 0) ? BASE_VALUE : DEFAULT_VALUE); /* This guarantees that PE set initial value before peer change one */ for ( j = 0; j < _SHMEM_COLLECT_SYNC_SIZE; j++ ) { pSync[j] = _SHMEM_SYNC_VALUE; } shmem_barrier_all(); /* Put value to peer */ if ((my_proc % 2) == 0) { FUNC_VALUE(shmem_addr, send_addr, 1, root_proc, 0, 1, ((num_proc / 2) + (num_proc % 2)), pSync); } /* Get value put by peer: * These routines start the remote transfer and may return before the data * is delivered to the remote PE */ shmem_barrier_all(); { int wait = WAIT_COUNT; while (wait--) { value = *shmem_addr; if (expect_value == value) break; sleep(1); } } rc = (expect_value == value ? TC_PASS : TC_FAIL); log_debug(OSH_TC, "my#%d root(#%d:%lld) expected = %lld actual = %lld\n", my_proc, root_proc, (INT64_TYPE)peer_value, (INT64_TYPE)expect_value, (INT64_TYPE)value); } else { rc = TC_SETUP_FAIL; } if (send_addr) { shfree(send_addr); } if (shmem_addr) { shfree(shmem_addr); } return rc; }
static int ProcXF86BigfontQueryFont( ClientPtr client) { FontPtr pFont; REQUEST(xXF86BigfontQueryFontReq); CARD32 stuff_flags; xCharInfo* pmax; xCharInfo* pmin; int nCharInfos; int shmid; #ifdef HAS_SHM ShmDescPtr pDesc; #else #define pDesc 0 #endif xCharInfo* pCI; CARD16* pIndex2UniqIndex; CARD16* pUniqIndex2Index; CARD32 nUniqCharInfos; #if 0 REQUEST_SIZE_MATCH(xXF86BigfontQueryFontReq); #else switch (client->req_len) { case 2: /* client with version 1.0 libX11 */ stuff_flags = (LocalClient(client) && !client->swapped ? XF86Bigfont_FLAGS_Shm : 0); break; case 3: /* client with version 1.1 libX11 */ stuff_flags = stuff->flags; break; default: return BadLength; } #endif client->errorValue = stuff->id; /* EITHER font or gc */ pFont = (FontPtr)SecurityLookupIDByType(client, stuff->id, RT_FONT, SecurityReadAccess); if (!pFont) { /* can't use VERIFY_GC because it might return BadGC */ GC *pGC = (GC *) SecurityLookupIDByType(client, stuff->id, RT_GC, SecurityReadAccess); if (!pGC) { client->errorValue = stuff->id; return BadFont; /* procotol spec says only error is BadFont */ } pFont = pGC->font; } pmax = FONTINKMAX(pFont); pmin = FONTINKMIN(pFont); nCharInfos = (pmax->rightSideBearing == pmin->rightSideBearing && pmax->leftSideBearing == pmin->leftSideBearing && pmax->descent == pmin->descent && pmax->ascent == pmin->ascent && pmax->characterWidth == pmin->characterWidth) ? 0 : N2dChars(pFont); shmid = -1; pCI = NULL; pIndex2UniqIndex = NULL; pUniqIndex2Index = NULL; nUniqCharInfos = 0; if (nCharInfos > 0) { #ifdef HAS_SHM if (!badSysCall) pDesc = (ShmDescPtr) FontGetPrivate(pFont, FontShmdescIndex); else pDesc = NULL; if (pDesc) { pCI = (xCharInfo *) pDesc->attach_addr; if (stuff_flags & XF86Bigfont_FLAGS_Shm) shmid = pDesc->shmid; } else { if (stuff_flags & XF86Bigfont_FLAGS_Shm && !badSysCall) pDesc = shmalloc(nCharInfos * sizeof(xCharInfo) + sizeof(CARD32)); if (pDesc) { pCI = (xCharInfo *) pDesc->attach_addr; shmid = pDesc->shmid; } else { #endif pCI = (xCharInfo *) ALLOCATE_LOCAL(nCharInfos * sizeof(xCharInfo)); if (!pCI) return BadAlloc; #ifdef HAS_SHM } #endif /* Fill nCharInfos starting at pCI. */ { xCharInfo* prCI = pCI; int ninfos = 0; int ncols = pFont->info.lastCol - pFont->info.firstCol + 1; int row; for (row = pFont->info.firstRow; row <= pFont->info.lastRow && ninfos < nCharInfos; row++) { unsigned char chars[512]; xCharInfo* tmpCharInfos[256]; unsigned long count; int col; unsigned long i; i = 0; for (col = pFont->info.firstCol; col <= pFont->info.lastCol; col++) { chars[i++] = row; chars[i++] = col; } (*pFont->get_metrics) (pFont, ncols, chars, TwoD16Bit, &count, tmpCharInfos); for (i = 0; i < count && ninfos < nCharInfos; i++) { *prCI++ = *tmpCharInfos[i]; ninfos++; } } } #ifdef HAS_SHM if (pDesc && !badSysCall) { *(CARD32 *)(pCI + nCharInfos) = signature; if (!FontSetPrivate(pFont, FontShmdescIndex, pDesc)) { shmdealloc(pDesc); return BadAlloc; } } } #endif if (shmid == -1) { /* Cannot use shared memory, so remove-duplicates the xCharInfos using a temporary hash table. */ /* Note that CARD16 is suitable as index type, because nCharInfos <= 0x10000. */ CARD32 hashModulus; CARD16* pHash2UniqIndex; CARD16* pUniqIndex2NextUniqIndex; CARD32 NextIndex; CARD32 NextUniqIndex; CARD16* tmp; CARD32 i, j; hashModulus = 67; if (hashModulus > nCharInfos+1) hashModulus = nCharInfos+1; tmp = (CARD16*) ALLOCATE_LOCAL((4*nCharInfos+1) * sizeof(CARD16)); if (!tmp) { if (!pDesc) DEALLOCATE_LOCAL(pCI); return BadAlloc; } pIndex2UniqIndex = tmp; /* nCharInfos elements */ pUniqIndex2Index = tmp + nCharInfos; /* max. nCharInfos elements */ pUniqIndex2NextUniqIndex = tmp + 2*nCharInfos; /* max. nCharInfos elements */ pHash2UniqIndex = tmp + 3*nCharInfos; /* hashModulus (<= nCharInfos+1) elements */ /* Note that we can use 0xffff as end-of-list indicator, because even if nCharInfos = 0x10000, 0xffff can not occur as valid entry before the last element has been inserted. And once the last element has been inserted, we don't need the hash table any more. */ for (j = 0; j < hashModulus; j++) pHash2UniqIndex[j] = (CARD16)(-1); NextUniqIndex = 0; for (NextIndex = 0; NextIndex < nCharInfos; NextIndex++) { xCharInfo* p = &pCI[NextIndex]; CARD32 hashCode = hashCI(p) % hashModulus; for (i = pHash2UniqIndex[hashCode]; i != (CARD16)(-1); i = pUniqIndex2NextUniqIndex[i]) { j = pUniqIndex2Index[i]; if (pCI[j].leftSideBearing == p->leftSideBearing && pCI[j].rightSideBearing == p->rightSideBearing && pCI[j].characterWidth == p->characterWidth && pCI[j].ascent == p->ascent && pCI[j].descent == p->descent && pCI[j].attributes == p->attributes) break; } if (i != (CARD16)(-1)) { /* Found *p at Index j, UniqIndex i */ pIndex2UniqIndex[NextIndex] = i; } else { /* Allocate a new entry in the Uniq table */ if (hashModulus <= 2*NextUniqIndex && hashModulus < nCharInfos+1) { /* Time to increate hash table size */ hashModulus = 2*hashModulus+1; if (hashModulus > nCharInfos+1) hashModulus = nCharInfos+1; for (j = 0; j < hashModulus; j++) pHash2UniqIndex[j] = (CARD16)(-1); for (i = 0; i < NextUniqIndex; i++) pUniqIndex2NextUniqIndex[i] = (CARD16)(-1); for (i = 0; i < NextUniqIndex; i++) { j = pUniqIndex2Index[i]; p = &pCI[j]; hashCode = hashCI(p) % hashModulus; pUniqIndex2NextUniqIndex[i] = pHash2UniqIndex[hashCode]; pHash2UniqIndex[hashCode] = i; } p = &pCI[NextIndex]; hashCode = hashCI(p) % hashModulus; } i = NextUniqIndex++; pUniqIndex2NextUniqIndex[i] = pHash2UniqIndex[hashCode]; pHash2UniqIndex[hashCode] = i; pUniqIndex2Index[i] = NextIndex; pIndex2UniqIndex[NextIndex] = i; } } nUniqCharInfos = NextUniqIndex; /* fprintf(stderr, "font metrics: nCharInfos = %d, nUniqCharInfos = %d, hashModulus = %d\n", nCharInfos, nUniqCharInfos, hashModulus); */ } } { int nfontprops = pFont->info.nprops; int rlength = sizeof(xXF86BigfontQueryFontReply) + nfontprops * sizeof(xFontProp) + (nCharInfos > 0 && shmid == -1 ? nUniqCharInfos * sizeof(xCharInfo) + (nCharInfos+1)/2 * 2 * sizeof(CARD16) : 0); xXF86BigfontQueryFontReply* reply = (xXF86BigfontQueryFontReply *) ALLOCATE_LOCAL(rlength); char* p; if (!reply) { if (nCharInfos > 0) { if (shmid == -1) DEALLOCATE_LOCAL(pIndex2UniqIndex); if (!pDesc) DEALLOCATE_LOCAL(pCI); } return BadAlloc; } reply->type = X_Reply; reply->length = (rlength - sizeof(xGenericReply)) >> 2; reply->sequenceNumber = client->sequence; reply->minBounds = pFont->info.ink_minbounds; reply->maxBounds = pFont->info.ink_maxbounds; reply->minCharOrByte2 = pFont->info.firstCol; reply->maxCharOrByte2 = pFont->info.lastCol; reply->defaultChar = pFont->info.defaultCh; reply->nFontProps = pFont->info.nprops; reply->drawDirection = pFont->info.drawDirection; reply->minByte1 = pFont->info.firstRow; reply->maxByte1 = pFont->info.lastRow; reply->allCharsExist = pFont->info.allExist; reply->fontAscent = pFont->info.fontAscent; reply->fontDescent = pFont->info.fontDescent; reply->nCharInfos = nCharInfos; reply->nUniqCharInfos = nUniqCharInfos; reply->shmid = shmid; reply->shmsegoffset = 0; if (client->swapped) { char tmp; swaps(&reply->sequenceNumber, tmp); swapl(&reply->length, tmp); swapCharInfo(&reply->minBounds); swapCharInfo(&reply->maxBounds); swaps(&reply->minCharOrByte2, tmp); swaps(&reply->maxCharOrByte2, tmp); swaps(&reply->defaultChar, tmp); swaps(&reply->nFontProps, tmp); swaps(&reply->fontAscent, tmp); swaps(&reply->fontDescent, tmp); swapl(&reply->nCharInfos, tmp); swapl(&reply->nUniqCharInfos, tmp); swapl(&reply->shmid, tmp); swapl(&reply->shmsegoffset, tmp); } p = (char*) &reply[1]; { FontPropPtr pFP; xFontProp* prFP; int i; for (i = 0, pFP = pFont->info.props, prFP = (xFontProp *) p; i < nfontprops; i++, pFP++, prFP++) { prFP->name = pFP->name; prFP->value = pFP->value; if (client->swapped) { char tmp; swapl(&prFP->name, tmp); swapl(&prFP->value, tmp); } } p = (char*) prFP; } if (nCharInfos > 0 && shmid == -1) { xCharInfo* pci; CARD16* ps; int i, j; pci = (xCharInfo*) p; for (i = 0; i < nUniqCharInfos; i++, pci++) { *pci = pCI[pUniqIndex2Index[i]]; if (client->swapped) swapCharInfo(pci); } ps = (CARD16*) pci; for (j = 0; j < nCharInfos; j++, ps++) { *ps = pIndex2UniqIndex[j]; if (client->swapped) { char tmp; swaps(ps, tmp); } } } WriteToClient(client, rlength, (char *)reply); DEALLOCATE_LOCAL(reply); if (nCharInfos > 0) { if (shmid == -1) DEALLOCATE_LOCAL(pIndex2UniqIndex); if (!pDesc) DEALLOCATE_LOCAL(pCI); } return (client->noClientException); } }
void foo(void){ shared int *sptr; sptr = shmalloc(57); free(sptr); /* Should generate an error. */ }
int main(int argc, char *argv[]) { int provided, ret, size, rank; int nextpe, i; static char src[BUF_SIZE]; char *dest; MPI_Status status[2]; MPI_Request req[2]; ret = MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &provided); if (ret != MPI_SUCCESS) { printf("Error initializing MPI with threads\n"); exit(1); } MPI_Comm_size(MPI_COMM_WORLD, &size); MPI_Comm_rank(MPI_COMM_WORLD, &rank); nextpe = (rank + 1) % size; //src = rank; dest = (char *) shmalloc (BUF_SIZE * sizeof (*dest)); if (dest == NULL){ printf("Couldn't shmalloc.\n"); } for ( i = 0; i < BUF_SIZE; i++){ dest[i] = 'z'; src[i] = BUF_SIZE * rank + i; } shmem_barrier_all (); //shmem_int_put (dest, &src, 1, nextpe); printf("Sending: %d to %d from %d\n\n", src[0], nextpe, rank); MPI_Isend(&src, BUF_SIZE, MPI_CHAR, nextpe, 123, MPI_COMM_WORLD, &req[0]); int flag = -1; MPI_Test( &req[0], &flag, &status[0]); // shmem_int_get (dest, &src, 1, nextpe); MPI_Irecv(dest, BUF_SIZE, MPI_CHAR, nextpe, 123, MPI_COMM_WORLD, &req[1]); MPI_Test( &req[1], &flag, &status[1]); shmem_barrier_all (); printf ("Rank: %4d: got[5] %4d, %4d: ", rank, dest[5],src[5]); if (dest[0] == rank * BUF_SIZE) { printf ("CORRECT"); } else { printf ("WRONG, expected %d", rank); } printf ("\n"); shmem_barrier_all (); /* static int value; int old; value = rank + 1; old = shmem_int_cswap (&value, value, -value, rank); printf ("%d: value = %d, old = %d\n", rank, value, old); static int race_winner = -4; int oldval; oldval = shmem_int_cswap (&race_winner, -4, rank, 0); if (oldval == -4){ printf ("pe %d was first\n", rank); } */ //shfree (dest); return 0; }
static int test_item4(void) { int rc = TC_PASS; TYPE_VALUE* target_addr = NULL; TYPE_VALUE* source_addr = NULL; TYPE_VALUE source_value = 0; TYPE_VALUE expect_value = 0; int num_proc = 0; int my_proc = 0; num_proc = _num_pes(); my_proc = _my_pe(); pWrk = shmalloc(sizeof(*pWrk) * sys_max(1/2 + 1, _SHMEM_REDUCE_MIN_WRKDATA_SIZE)); if (pWrk) { source_addr = shmalloc(sizeof(*source_addr)); target_addr = source_addr; } if (target_addr && source_addr) { TYPE_VALUE value = DEFAULT_VALUE; int j = 0; /* Set my value */ source_value = (TYPE_VALUE)my_proc; *source_addr = source_value; /* Define expected value */ expect_value = 0; /* This guarantees that PE set initial value before peer change one */ for ( j = 0; j < _SHMEM_REDUCE_SYNC_SIZE; j++ ) { pSync[j] = _SHMEM_SYNC_VALUE; } shmem_barrier_all(); /* Put value to peer */ FUNC_VALUE(target_addr, source_addr, 1, 0, 0, num_proc, pWrk, pSync); /* Get value put by peer: * These routines start the remote transfer and may return before the data * is delivered to the remote PE */ shmem_barrier_all(); { int total_wait = 0; while (*target_addr == DEFAULT_VALUE && total_wait < 1000 * WAIT_COUNT) { total_wait++; usleep(1); } value = *target_addr; } rc = (expect_value == value ? TC_PASS : TC_FAIL); log_debug(OSH_TC, "my#%d source = %lld expected = %lld actual = %lld\n", my_proc, (INT64_TYPE)source_value, (INT64_TYPE)expect_value, (INT64_TYPE)value); } else { rc = TC_SETUP_FAIL; } if (source_addr) { shfree(source_addr); } if (pWrk) { shfree(pWrk); pWrk = NULL; } return rc; }
static int open_remap_ghost(struct reg_file_info *rfi, RemapFilePathEntry *rfe) { struct ghost_file *gf; GhostFileEntry *gfe = NULL; struct cr_img *img; list_for_each_entry(gf, &ghost_files, list) if (gf->id == rfe->remap_id) goto gf_found; /* * Ghost not found. We will create one in the same dir * as the very first client of it thus resolving any * issues with cross-device links. */ pr_info("Opening ghost file %#x for %s\n", rfe->remap_id, rfi->path); gf = shmalloc(sizeof(*gf)); if (!gf) return -1; gf->remap.rpath = xmalloc(PATH_MAX); if (!gf->remap.rpath) goto err; img = open_image(CR_FD_GHOST_FILE, O_RSTR, rfe->remap_id); if (!img) goto err; if (pb_read_one(img, &gfe, PB_GHOST_FILE) < 0) goto close_ifd; /* * For old formats where optional has_[dev|ino] is * not present we will have zeros here which is quite * a sign for "absent" fields. */ gf->dev = gfe->dev; gf->ino = gfe->ino; gf->remap.rmnt_id = rfi->rfe->mnt_id; if (S_ISDIR(gfe->mode)) strncpy(gf->remap.rpath, rfi->path, PATH_MAX); else ghost_path(gf->remap.rpath, PATH_MAX, rfi, rfe); if (create_ghost(gf, gfe, img)) goto close_ifd; ghost_file_entry__free_unpacked(gfe, NULL); close_image(img); gf->id = rfe->remap_id; gf->remap.users = 0; gf->remap.is_dir = S_ISDIR(gfe->mode); gf->remap.owner = gfe->uid; list_add_tail(&gf->list, &ghost_files); gf_found: rfi->remap = &gf->remap; return 0; close_ifd: close_image(img); err: if (gfe) ghost_file_entry__free_unpacked(gfe, NULL); xfree(gf->remap.rpath); shfree_last(gf); return -1; }
int main(int argc, char * argv[]) { time_t start_t, end_t; int i; double seconds; for (i = 0; i < SHMEM_BCAST_SYNC_SIZE; i += 1) { pSync[i] = _SHMEM_SYNC_VALUE; } start_pes(0); me = shmem_my_pe(); npes = shmem_n_pes(); srand(me*time(NULL)); int N; N = atoi (argv[1]); //printf(" N = %d\n",N); //based on this N generate N/npes length sequence in each processor. Merge sort each sequence in the different processes. Then recurse is called upon to perform the interprocessor merge operation. A = (int *)shmalloc(N*sizeof(int)); Aux = (int *)shmalloc(N*sizeof(int)); if(A == NULL) { printf("Out of Memory\n"); return 1; } if(Aux == NULL) { printf("Out of Memory\n"); return 1; } for(i =0 ; i< N/npes; i++) { A[i] = rand()%(100000-0); } shmem_barrier_all(); /* printf("DEBUG(%d)the unsorted elements: ",me); for(i=0;i< N/npes; i++){ printf("%d ,",A[i] ); }*/ //recurse (1,2, npes,1); printf("\n"); start_t = time(NULL); mergesort(0,N/npes-1); shmem_barrier_all(); /* printf("DEBUG(%d)the sorted elements: ",me); for(i=0;i< N/npes; i++){ printf("%d ,",A[i] ); }*/ recurse (1,2, npes,1, N/npes); end_t = time(NULL); seconds = difftime(end_t, start_t); if(me == 0) { printf("\nTime taken : %f\n",seconds); printf("\n(%d)The sorted list:\n",me); for(i=0 ; i< N; i++) { printf("A[%d] = %d \n", i, A[i]); } } shfree(Aux); shfree(A); shmem_finalize(); }
static int test_item8(void) { int rc = TC_PASS; static TYPE_VALUE target_addr[MAX_BUFFER_SIZE * 2]; static TYPE_VALUE source_addr[MAX_BUFFER_SIZE * 2]; TYPE_VALUE source_value = 0; TYPE_VALUE expect_value = 0; int num_proc = 0; int my_proc = 0; long* pSyncMult = NULL; TYPE_VALUE* pWrkMult = NULL; int pSyncNum = 2; int pWrkNum = 2; num_proc = _num_pes(); my_proc = _my_pe(); pSyncMult = shmalloc(sizeof(*pSyncMult) * pSyncNum * _SHMEM_REDUCE_SYNC_SIZE); if (pSyncMult) { TYPE_VALUE value = DEFAULT_VALUE; int i = 0; int j = 0; long cur_buf_size = 0; for ( j = 0; j < pSyncNum * _SHMEM_REDUCE_SYNC_SIZE; j++ ) { pSyncMult[j] = _SHMEM_SYNC_VALUE; } /* Give some time to all PE for setting their values */ shmem_barrier_all(); pWrkMult = shmalloc(sizeof(*pWrkMult) * pWrkNum * sys_max(MAX_BUFFER_SIZE, _SHMEM_REDUCE_MIN_WRKDATA_SIZE)); if (pWrkMult) { value = DEFAULT_VALUE; source_value = (TYPE_VALUE)(BASE_VALUE + my_proc); fill_buffer((void *)source_addr, MAX_BUFFER_SIZE * 2, (void *)&source_value, sizeof(source_value)); fill_buffer((void *)target_addr, MAX_BUFFER_SIZE * 2, (void *)&value, sizeof(value)); shmem_barrier_all(); for (i = 0; (i < __cycle_count) && (rc == TC_PASS); i++) { cur_buf_size = sys_max(1, (i + 1) * MAX_BUFFER_SIZE / __cycle_count); /* Set initial target value */ value = DEFAULT_VALUE; /* Set my value */ source_value = (TYPE_VALUE)(BASE_VALUE + my_proc); /* Define expected value */ expect_value = ( my_proc % 2 ? DEFAULT_VALUE : BASE_VALUE ); /* Put value to peer */ FUNC_VALUE(target_addr + (i % 2) * MAX_BUFFER_SIZE, source_addr + (i % 2) * MAX_BUFFER_SIZE, cur_buf_size, 0, 1, ((num_proc / 2) + (num_proc % 2)), pWrkMult + (i % pWrkNum) * sys_max(MAX_BUFFER_SIZE, _SHMEM_REDUCE_MIN_WRKDATA_SIZE), pSyncMult + (i % pSyncNum) * _SHMEM_REDUCE_SYNC_SIZE); rc = (!compare_buffer_with_const(target_addr + (i % 2) * MAX_BUFFER_SIZE, cur_buf_size, &expect_value, sizeof(expect_value)) ? TC_PASS : TC_FAIL); log_debug(OSH_TC, "my#%d source = %lld expected = %lld actual = %lld buffer size = %lld\n", my_proc, (INT64_TYPE)source_value, (INT64_TYPE)expect_value, (INT64_TYPE)value, (INT64_TYPE)cur_buf_size); if (rc) { TYPE_VALUE* check_addr = target_addr + (i % 2) * MAX_BUFFER_SIZE; int odd_index = compare_buffer_with_const(check_addr, cur_buf_size, &expect_value, sizeof(expect_value)); int show_index = (odd_index > 1 ? odd_index - 2 : 0); int show_size = sizeof(*check_addr) * sys_min(3, cur_buf_size - odd_index - 1); log_debug(OSH_TC, "index of incorrect value: 0x%08X (%d)\n", odd_index - 1, odd_index - 1); log_debug(OSH_TC, "buffer interval: 0x%08X - 0x%08X\n", show_index, show_index + show_size); show_buffer(check_addr + show_index, show_size); } fill_buffer((void *)(source_addr + (i % 2) * MAX_BUFFER_SIZE), cur_buf_size, (void *)&source_value, sizeof(source_value)); fill_buffer((void *)(target_addr + (i % 2) * MAX_BUFFER_SIZE ), cur_buf_size, (void *)&value, sizeof(value)); } shfree(pWrkMult); } else { rc = TC_SETUP_FAIL; } shfree(pSyncMult); } else { rc = TC_SETUP_FAIL; } return rc; }
/**************************************************************************** * Test Case processing procedure ***************************************************************************/ int osh_reduce_tc22(const TE_NODE *node, int argc, const char *argv[]) { int rc = TC_PASS; rc = __parse_opt(node, argc, argv); if (rc == TC_PASS) { pSync = shmalloc(sizeof(*pSync) * _SHMEM_REDUCE_SYNC_SIZE); if (!pSync) { rc = TC_SETUP_FAIL; } } else { rc = TC_SETUP_FAIL; } /* Every PE does reduction of the single value as symmetric data object to itself */ if (rc == TC_PASS) { rc = test_item1(); log_item(node, 1, rc); shmem_barrier_all(); } /* All PEs reduce the single value */ if (rc == TC_PASS) { rc = test_item2(); log_item(node, 2, rc); shmem_barrier_all(); } /* Every PE does reduction of the single value as symmetric data object to itself * (target and source are the same array) */ if (rc == TC_PASS) { rc = test_item3(); log_item(node, 3, rc); shmem_barrier_all(); } /* All PEs reduce the single value * (target and source are the same array) */ if (rc == TC_PASS) { rc = test_item4(); log_item(node, 4, rc); shmem_barrier_all(); } /* Every PE does reduction of the buffer as symmetric data object to itself */ if (rc == TC_PASS) { rc = test_item5(); log_item(node, 5, rc); shmem_barrier_all(); } /* All PEs reduce the buffer */ if (rc == TC_PASS) { rc = test_item6(); log_item(node, 6, rc); shmem_barrier_all(); } /* Even PEs reduce the buffer */ if (rc == TC_PASS) { rc = test_item7(); log_item(node, 7, rc); shmem_barrier_all(); } /* reduce calls in loop with alternating multiple pSync and pWrk arrays (without barrrier synchronization between iterations) */ if (rc == TC_PASS) { rc = test_item8(); log_item(node, 8, rc); shmem_barrier_all(); } if (pSync) { shfree(pSync); } return rc; }
static int test_item7(void) { int rc = TC_PASS; TYPE_VALUE* target_addr = NULL; TYPE_VALUE* source_addr = NULL; TYPE_VALUE source_value = 0; TYPE_VALUE expect_value = 0; int num_proc = 0; int my_proc = 0; num_proc = _num_pes(); my_proc = _my_pe(); target_addr = (TYPE_VALUE*)shmalloc(sizeof(*target_addr) * __max_buffer_size); source_addr = (TYPE_VALUE*)shmalloc(sizeof(*source_addr) * __max_buffer_size); if (target_addr && source_addr) { TYPE_VALUE value = DEFAULT_VALUE; int i = 0; int j = 0; long cur_buf_size = 0; for (i = 0; (i < __cycle_count) && (rc == TC_PASS); i++) { cur_buf_size = sys_max(1, (i + 1) * __max_buffer_size / __cycle_count); pWrk = shmalloc(sizeof(*pWrk) * sys_max(cur_buf_size/2 + 1, _SHMEM_REDUCE_MIN_WRKDATA_SIZE)); if (pWrk) { /* Set initial target value */ value = DEFAULT_VALUE; fill_buffer((void *)target_addr, cur_buf_size, (void *)&value, sizeof(value)); /* Give some time to all PE for setting their values */ shmem_barrier_all(); /* Set my value */ source_value = (TYPE_VALUE)(BASE_VALUE + my_proc); fill_buffer((void *)source_addr, cur_buf_size, (void *)&source_value, sizeof(source_value)); /* Define expected value */ expect_value = ( my_proc % 2 ? DEFAULT_VALUE : BASE_VALUE ); /* This guarantees that PE set initial value before peer change one */ for ( j = 0; j < _SHMEM_REDUCE_SYNC_SIZE; j++ ) { pSync[j] = _SHMEM_SYNC_VALUE; } shmem_barrier_all(); /* Put value to peer */ FUNC_VALUE(target_addr, source_addr, cur_buf_size, 0, 1, ((num_proc / 2) + (num_proc % 2)), pWrk, pSync); /* Get value put by peer: * These routines start the remote transfer and may return before the data * is delivered to the remote PE */ shmem_barrier_all(); { int wait = WAIT_COUNT; while (wait--) { value = *target_addr; if (expect_value == value) break; sleep(1); } } rc = (!compare_buffer_with_const(target_addr, cur_buf_size, &expect_value, sizeof(expect_value)) ? TC_PASS : TC_FAIL); log_debug(OSH_TC, "my#%d source = %lld expected = %lld actual = %lld buffer size = %lld\n", my_proc, (INT64_TYPE)source_value, (INT64_TYPE)expect_value, (INT64_TYPE)value, (INT64_TYPE)cur_buf_size); if (rc) { TYPE_VALUE* check_addr = target_addr; int odd_index = compare_buffer_with_const(check_addr, cur_buf_size, &expect_value, sizeof(expect_value)); int show_index = (odd_index > 1 ? odd_index - 2 : 0); int show_size = sizeof(*check_addr) * sys_min(3, cur_buf_size - odd_index - 1); log_debug(OSH_TC, "index of incorrect value: 0x%08X (%d)\n", odd_index - 1, odd_index - 1); log_debug(OSH_TC, "buffer interval: 0x%08X - 0x%08X\n", show_index, show_index + show_size); show_buffer(check_addr + show_index, show_size); } shfree(pWrk); } else { rc = TC_SETUP_FAIL; } } } else { rc = TC_SETUP_FAIL; } if (source_addr) { shfree(source_addr); } if (target_addr) { shfree(target_addr); } return rc; }
/**************************************************************************** * Test Case processing procedure ***************************************************************************/ int osh_coll_tc1(const TE_NODE *node, int argc, const char *argv[]) { int rc = TC_PASS; rc = __parse_opt(node, argc, argv); if (rc == TC_PASS) { pSync = shmalloc(sizeof(*pSync) * _SHMEM_COLLECT_SYNC_SIZE); if (!pSync) { rc = TC_SETUP_FAIL; } } /* Every PE put the single value as symmetric data object to itself * The data is not copied to the target address on the PE specified by PE_root. */ if (rc == TC_PASS) { rc = test_item1(); log_item(node, 1, rc); shmem_barrier_all(); } /* PE#0 put defined single value to all */ if (rc == TC_PASS) { rc = test_item2(); log_item(node, 2, rc); shmem_barrier_all(); } /* Random PE put defined single value to all */ if (rc == TC_PASS) { rc = test_item3(); log_item(node, 3, rc); shmem_barrier_all(); } /* PE#0 put defined single value to even PEs */ if (rc == TC_PASS) { rc = test_item4(); log_item(node, 4, rc); shmem_barrier_all(); } /* PE#0 put dynamic buffer to even PEs */ if (rc == TC_PASS) { rc = test_item5(); log_item(node, 5, rc); shmem_barrier_all(); } /* PE#0 put static buffer to even PEs */ if (rc == TC_PASS) { rc = test_item6(); log_item(node, 6, rc); shmem_barrier_all(); } /* broadcast calls in loop with alternating multiple pSync arrays (without barrrier synchronization between iterations) */ if (rc == TC_PASS) { rc = test_item7(); log_item(node, 7, rc); shmem_barrier_all(); } if (pSync) { shfree(pSync); } return rc; }
/* Performance test for shmem_XX_get (latency and bandwidth) */ #include <stdio.h> #include <stdlib.h> #include <time.h> #include <sys/time.h> #include <shmem.h> long double time_taken; long pSync[_SHMEM_REDUCE_SYNC_SIZE]; long double pWrk[_SHMEM_REDUCE_MIN_WRKDATA_SIZE]; //#define N_ELEMENTS 25600/*Data size chosen to be able to capture time required*/ int main(void) { int i,j,k; int *target; int *source; int me, npes; int nxtpe; struct timeval start, end; long double start_time,end_time; int N_ELEMENTS = (4194304*2)/sizeof(int); start_pes(0); me = _my_pe(); npes = _num_pes(); for (i = 0; i < SHMEM_BCAST_SYNC_SIZE; i += 1) { pSync[i] = _SHMEM_SYNC_VALUE; } nxtpe = (me+1)%npes; source = (int *) shmalloc( N_ELEMENTS * sizeof(*source) ); target = (int *) shmalloc( N_ELEMENTS * sizeof(*target) ); if(me == 0) printf("Get Performance test results:\nSize (Bytes)\t\tTime (Microseconds)\t\tBandwidth (Bytes/Second)\n"); for (i = 0; i < N_ELEMENTS; i += 1) { source[i] = i + 1; target[i] = -90; } shmem_barrier_all(); /*For int put we take average of all the times realized by a pair of PEs, thus * reducing effects of physical location of PEs*/ for (i=1;i<=N_ELEMENTS;i=i*2) { time_taken = 0; for(j=0;j<10000;j++){ gettimeofday(&start, NULL); start_time = (start.tv_sec * 1000000.0) + start.tv_usec; shmem_int_get(target, source, i,nxtpe); gettimeofday(&end, NULL); end_time = (end.tv_sec * 1000000.0) + end.tv_usec; time_taken = time_taken + (end_time - start_time); } shmem_longdouble_sum_to_all(&time_taken, &time_taken,1, 0, 0, npes, pWrk, pSync); if(me == 0){ time_taken = time_taken/(npes*10000); /*Average time across all PEs for one put*/ if (i*sizeof(i) < 1048576) printf("%ld \t\t\t\t %ld\t\t\t\t %ld\n",i*sizeof(i),time_taken,(i*sizeof(i))/(time_taken*1000000.0)); else printf("%ld \t\t\t %ld\t\t\t\t %ld\n",i*sizeof(i),time_taken,(i*sizeof(i))/(time_taken*1000000.0)); } } shmem_barrier_all(); shfree(target); shfree(source); return 0; }
int init_csg_field(const int V) { int i = 0, j = 0, sum = 0; spinor * s; for(i = 0; i < no_monomials; i++) { sum += monomial_list[i].csg_N; sum += monomial_list[i].csg_N2; } /* if all histories are zero, we do not need initialisation */ if(sum != 0) { #if (defined _USE_SHMEM && !(defined _USE_HALFSPINOR)) sp_csg = (spinor*)shmalloc((sum*V+1)*sizeof(spinor)); #else sp_csg = (spinor*)calloc(sum*V+1, sizeof(spinor)); #endif if(errno == ENOMEM) { return(1); } for(i = 0; i < no_monomials; i++) { monomial_list[i].csg_field = malloc((monomial_list[i].csg_N+1)*sizeof(spinor*)); if(errno == ENOMEM) { return(2); } monomial_list[i].csg_field2 = malloc(monomial_list[i].csg_N2*sizeof(spinor*)); if(errno == ENOMEM) { return(2); } } #if ( defined SSE || defined SSE2 || defined SSE3) s = (spinor*)(((unsigned long int)(sp_csg)+ALIGN_BASE)&~ALIGN_BASE); #else s = sp_csg; #endif for(j = 0; j < no_monomials; j++) { if(monomial_list[j].csg_N != 0) { for(i = 0; i < monomial_list[j].csg_N; i++) { monomial_list[j].csg_field[i] = s; s = s + V; } } } for(j = 0; j < no_monomials; j++) { if(monomial_list[j].csg_N2 != 0) { for(i = 0; i < monomial_list[j].csg_N2; i++) { monomial_list[j].csg_field2[i] = s; s = s + V; } } } monomial_list[0].csg_index_array = (int*) malloc(sum*sizeof(int)); for(i = 1; i < no_monomials; i++) { monomial_list[i].csg_index_array = monomial_list[i-1].csg_index_array + monomial_list[i-1].csg_N; } monomial_list[0].csg_index_array2 = monomial_list[no_monomials-1].csg_index_array + monomial_list[no_monomials-1].csg_N; for(i = 1; i < no_monomials; i++) { monomial_list[i].csg_index_array2 = monomial_list[i-1].csg_index_array2 + monomial_list[i-1].csg_N2; } } return(0); }
static int test_item3(void) { int rc = TC_PASS; TYPE_VALUE* shmem_addr = NULL; TYPE_VALUE my_value = 0; TYPE_VALUE peer_value = 0; TYPE_VALUE expect_value = 0; int num_proc = 0; int my_proc = 0; int peer_proc = 0; num_proc = _num_pes(); my_proc = _my_pe(); shmem_addr = shmalloc(sizeof(*shmem_addr)); if (shmem_addr) { TYPE_VALUE value = -1; INT64_TYPE i = 0; my_value = 0; for (i = 0; i < COUNT_VALUE; i++) { /* Set my value */ my_value = (my_proc % 2 ? 1 : -1) * (i * STEP_VALUE); *shmem_addr = my_value; /* Wait is set instead of barrier to give some time to all PE for setting their values */ shmem_barrier_all(); /* Define peer and it value */ peer_proc = (my_proc + 1) % num_proc; peer_value = (peer_proc % 2 ? 1 : -1) * (i * STEP_VALUE); /* Define expected value */ expect_value = peer_value; /* Get value from peer */ value = FUNC_VALUE(shmem_addr, peer_proc); rc = (expect_value == value ? TC_PASS : TC_FAIL); log_debug(OSH_TC, "my(#%d:%lld) peer(#%d:%lld) expected = %lld vs got = %lld\n", my_proc, (INT64_TYPE)my_value, peer_proc, (INT64_TYPE)peer_value, (INT64_TYPE)expect_value, (INT64_TYPE)value); /* Wait is set instead of barrier to give some time to all PE for setting their values */ shmem_barrier_all(); } } else { rc = TC_SETUP_FAIL; } if (shmem_addr) { shfree(shmem_addr); } return rc; }