Imported Upstream version 6.10.0.49

Former-commit-id: 1d6753294b2993e1fbf92de9366bb9544db4189b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2020-01-16 16:38:04 +00:00
parent d94e79959b
commit 468663ddbb
48518 changed files with 2789335 additions and 61176 deletions

View File

@@ -0,0 +1,64 @@
// RUN: %libomp-compile && env OMP_CANCELLATION=true %libomp-run
// XFAIL: gcc
// Clang had a bug until version 4.0.1 which resulted in a hang.
// UNSUPPORTED: clang-3, clang-4.0.0
// Regression test for a bug in cancellation to cover effect of `#pragma omp cancel`
// in a loop construct, on sections construct.
// Pass condition: Cancellation status from `for` does not persist
// to `sections`.
#include <stdio.h>
#include <omp.h>
int result[2] = {0, 0};
void cq416850_for_sections() {
unsigned i;
// 1) loop
#pragma omp for
for (i = 0; i < 1; i++) {
result[0] = 1;
#pragma omp cancel for
result[0] = 2;
}
// printf("thread %d: result[0] = %d, result[1] = %d \n", omp_get_thread_num(), result[0], result[1]);
// 2) sections
#pragma omp sections
{
#pragma omp section
{
result[1] = 1;
#pragma omp cancellation point sections
result[1] = 2;
}
}
}
int main(void) {
if(!omp_get_cancellation()) {
printf("Cancellation not enabled!\n");
return 2;
}
#pragma omp parallel num_threads(4)
{
cq416850_for_sections();
}
if (result[0] != 1 || result[1] != 2) {
printf("Incorrect values. "
"result[0] = %d (expected 1), "
"result[1] = %d (expected 2).\n",
result[0], result[1]);
printf("FAILED\n");
return 1;
}
printf("PASSED\n");
return 0;
}

View File

@@ -0,0 +1,39 @@
// RUN: %libomp-compile-and-run
#include <stdio.h>
int main()
{
int i;
int i1 = 0;
int i2 = 1;
int i3 = 2;
int i4 = 3;
int i5 = 4;
int i6 = 6;
int i7 = 7;
int i8 = 8;
int i9 = 9;
int i10 = 10;
int i11 = 11;
int i12 = 12;
int i13 = 13;
int i14 = 14;
int i15 = 15;
int i16 = 16;
int r = 0;
#pragma omp parallel for firstprivate(i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15, i16) reduction(+:r)
for (i = 0; i < i16; i++) {
r += i + i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9 + i10 + i11 + i12 + i13 + i14 + i15 + i16;
}
int rf = 2216;
if (r != rf) {
fprintf(stderr, "r should be %d but instead equals %d\n", rf, r);
return 1;
}
return 0;
}

View File

@@ -0,0 +1,81 @@
// RUN: %libomp-compile -lpthread && %libomp-run
#include <stdio.h>
#include "omp_testsuite.h"
#define NUM_THREADS 10
/*
After hot teams were enabled by default, the library started using levels
kept in the team structure. The levels are broken in case foreign thread
exits and puts its team into the pool which is then re-used by another foreign
thread. The broken behavior observed is when printing the levels for each
new team, one gets 1, 2, 1, 2, 1, 2, etc. This makes the library believe that
every other team is nested which is incorrect. What is wanted is for the
levels to be 1, 1, 1, etc.
*/
int a = 0;
int level;
typedef struct thread_arg_t {
int iterations;
} thread_arg_t;
void* thread_function(void* arg) {
int i;
thread_arg_t* targ = (thread_arg_t*)arg;
int iterations = targ->iterations;
#pragma omp parallel private(i)
{
// level should always be 1
#pragma omp single
level = omp_get_level();
#pragma omp for
for(i = 0; i < iterations; i++) {
#pragma omp atomic
a++;
}
}
}
int test_omp_team_reuse()
{
int i;
int success = 1;
pthread_t thread[NUM_THREADS];
thread_arg_t thread_arg[NUM_THREADS];
// launch NUM_THREADS threads, one at a time to perform thread_function()
for(i = 0; i < NUM_THREADS; i++) {
thread_arg[i].iterations = i + 1;
pthread_create(thread+i, NULL, thread_function, thread_arg+i);
pthread_join(*(thread+i), NULL);
// level read in thread_function()'s parallel region should be 1
if(level != 1) {
fprintf(stderr, "error: for pthread %d level should be 1 but "
"instead equals %d\n", i, level);
success = 0;
}
}
// make sure the for loop works
int known_sum = (NUM_THREADS * (NUM_THREADS+1)) / 2;
if(a != known_sum) {
fprintf(stderr, "a should be %d but instead equals %d\n", known_sum, a);
success = 0;
}
return success;
}
int main()
{
int i;
int num_failed=0;
for(i = 0; i < REPETITIONS; i++) {
a = 0;
if(!test_omp_team_reuse()) {
num_failed++;
}
}
return num_failed;
}

View File

@@ -0,0 +1,64 @@
// RUN: %libomp-compile-and-run
//
// The test checks the teams construct pseudocode executed on host
//
#include <stdio.h>
#include <omp.h>
#ifndef N_TEAMS
#define N_TEAMS 4
#endif
#ifndef N_THR
#define N_THR 3
#endif
static int err = 0;
// Internal library staff to emulate compiler's code generation:
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
int reserved_1;
int flags;
int reserved_2;
int reserved_3;
char *psource;
} ident_t;
static ident_t dummy_loc = {0, 2, 0, 0, ";dummyFile;dummyFunc;0;0;;"};
int __kmpc_global_thread_num(void*);
void __kmpc_push_num_teams(ident_t const*, int, int, int);
void __kmpc_fork_teams(ident_t const*, int argc, void *microtask, ...);
#ifdef __cplusplus
}
#endif
// Outlined entry point:
void foo(int *gtid, int *tid, int *nt)
{ // start "serial" execution by master threads of each team
if ( nt ) {
printf(" team %d, param %d\n", omp_get_team_num(), *nt);
} else {
printf("ERROR: teams before parallel: gtid, tid: %d %d, bad pointer: %p\n", *gtid, *tid, nt);
err++;
return;
}
}
int main()
{
int nt = 4;
int th = __kmpc_global_thread_num(NULL); // registers initial thread
__kmpc_push_num_teams(&dummy_loc, th, N_TEAMS, N_THR);
__kmpc_fork_teams(&dummy_loc, 1, &foo, &nt); // pass 1 shared parameter "nt"
if (err)
printf("failed with %d errors\n",err);
else
printf("passed\n");
return err;
}

View File

@@ -0,0 +1,68 @@
// RUN: %libomp-compile-and-run
//
// The test checks the teams construct with reduction executed on the host.
//
#include <stdio.h>
#include <omp.h>
#include <stdint.h>
#ifndef N_TEAMS
#define N_TEAMS 4
#endif
#ifndef N_THR
#define N_THR 3
#endif
// Internal library stuff to emulate compiler's code generation:
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
int32_t reserved_1;
int32_t flags;
int32_t reserved_2;
int32_t reserved_3;
char const *psource;
} ident_t;
static ident_t dummy_loc = {0, 2, 0, 0, ";dummyFile;dummyFunc;0;0;;"};
typedef union {
// The global will be used as pointer, so we need to make sure that the
// compiler correctly aligns the global...
void *ptr;
int32_t data[8];
} kmp_critical_name;
kmp_critical_name crit;
int32_t __kmpc_global_thread_num(ident_t *);
void __kmpc_push_num_teams(ident_t *, int32_t global_tid, int32_t num_teams,
int32_t num_threads);
void __kmpc_fork_teams(ident_t *, int32_t argc, void *microtask, ...);
int32_t __kmpc_reduce(ident_t *, int32_t global_tid, int32_t num_vars,
size_t reduce_size, void *reduce_data, void *reduce_func,
kmp_critical_name *lck);
void __kmpc_end_reduce(ident_t *, int32_t global_tid, kmp_critical_name *lck);
#ifdef __cplusplus
}
#endif
// Outlined entry point:
void outlined(int32_t *gtid, int32_t *tid) {
int32_t ret = __kmpc_reduce(&dummy_loc, *gtid, 0, 0, NULL, NULL, &crit);
__kmpc_end_reduce(&dummy_loc, *gtid, &crit);
}
int main() {
int32_t th = __kmpc_global_thread_num(NULL); // registers initial thread
__kmpc_push_num_teams(&dummy_loc, th, N_TEAMS, N_THR);
__kmpc_fork_teams(&dummy_loc, 0, &outlined);
// Test did not hang -> passed!
printf("passed\n");
return 0;
}