This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gomp5] Tweak OMP_AFFINITY_FORMAT handling


Hi!

With the addition of host teams, it makes a lot of sense to be able to print
also the team number and number of teams.  This change made it into OpenMP
5.0, together with various changes to mostly the short names, but two long
names too.

The following adjusts our implementation to match what will appear in OpenMP
5.0:

2018-10-08  Jakub Jelinek  <jakub@redhat.com>

	* env.c (gomp_affinity_format_var): Use %i instead of %T and
	%A instead of %a.
	* affinity-fmt.c (affinity_types): Change short forms h to H,
	a to A, A to a and T to i.  Change long forms thread_level to
	nesting_level and thread_identifier to native_thread_id.  Add
	team_num/t and num_teams/T entries.
	(gomp_display_affinity): Adjust for the above changes.
	* testsuite/libgomp.c-c++-common/display-affinity-1.c: Likewise.
	Add test also for %{team_num}, %{num_teams}, %t and %T.
	* testsuite/libgomp.fortran/display-affinity-1.f90: Likewise.

--- libgomp/env.c.jj	2018-07-26 16:09:18.510102373 +0200
+++ libgomp/env.c	2018-10-08 12:37:39.126304066 +0200
@@ -89,7 +89,7 @@ unsigned long gomp_places_list_len;
 int gomp_debug_var;
 unsigned int gomp_num_teams_var;
 bool gomp_display_affinity_var;
-char *gomp_affinity_format_var = "level %L thread %T affinity %a";
+char *gomp_affinity_format_var = "level %L thread %i affinity %A";
 size_t gomp_affinity_format_len;
 char *goacc_device_type;
 int goacc_device_num;
--- libgomp/affinity-fmt.c.jj	2018-05-23 16:22:32.610813049 +0200
+++ libgomp/affinity-fmt.c	2018-10-08 13:27:41.021061844 +0200
@@ -237,14 +237,16 @@ static struct affinity_types_struct affi
 {
 #define AFFINITY_TYPE(l, s) \
   { #l, sizeof (#l) - 1, s }
-  AFFINITY_TYPE (thread_level, 'L'),
+  AFFINITY_TYPE (team_num, 't'),
+  AFFINITY_TYPE (num_teams, 'T'),
+  AFFINITY_TYPE (nesting_level, 'L'),
   AFFINITY_TYPE (thread_num, 'n'),
-  AFFINITY_TYPE (host, 'h'),
-  AFFINITY_TYPE (process_id, 'P'),
-  AFFINITY_TYPE (thread_identifier, 'T'),
   AFFINITY_TYPE (num_threads, 'N'),
-  AFFINITY_TYPE (ancestor_tnum, 'A'),
-  AFFINITY_TYPE (thread_affinity, 'a')
+  AFFINITY_TYPE (ancestor_tnum, 'a'),
+  AFFINITY_TYPE (host, 'H'),
+  AFFINITY_TYPE (process_id, 'P'),
+  AFFINITY_TYPE (native_thread_id, 'i'),
+  AFFINITY_TYPE (thread_affinity, 'A')
 #undef AFFINITY_TYPE
 };
 
@@ -324,13 +326,25 @@ gomp_display_affinity (char *buffer, siz
 	}
       switch (c)
 	{
+	case 't':
+	  val = omp_get_team_num ();
+	  goto do_int;
+	case 'T':
+	  val = omp_get_num_teams ();
+	  goto do_int;
 	case 'L':
 	  val = ts->level;
 	  goto do_int;
 	case 'n':
 	  val = ts->team_id;
 	  goto do_int;
-	case 'h':
+	case 'N':
+	  val = ts->team ? ts->team->nthreads : 1;
+	  goto do_int;
+	case 'a':
+	  val = ts->team ? ts->team->prev_ts.team_id : -1;
+	  goto do_int;
+	case 'H':
 	  gomp_display_hostname (buffer, size, &ret, right, sz);
 	  break;
 	case 'P':
@@ -340,7 +354,7 @@ gomp_display_affinity (char *buffer, siz
 	  val = 0;
 #endif
 	  goto do_int;
-	case 'T':
+	case 'i':
 #if defined(LIBGOMP_USE_PTHREADS) && defined(__GNUC__)
 	  /* Handle integral pthread_t.  */
 	  if (__builtin_classify_type (handle) == 1)
@@ -373,13 +387,7 @@ gomp_display_affinity (char *buffer, siz
 #endif
 	  val = 0;
 	  goto do_int;
-	case 'N':
-	  val = ts->team ? ts->team->nthreads : 1;
-	  goto do_int;
 	case 'A':
-	  val = ts->team ? ts->team->prev_ts.team_id : -1;
-	  goto do_int;
-	case 'a':
 	  if (sz == (size_t) -1)
 	    gomp_display_affinity_place (buffer, size, &ret,
 					 place - 1);
--- libgomp/testsuite/libgomp.c-c++-common/display-affinity-1.c.jj	2018-05-23 11:21:57.641972727 +0200
+++ libgomp/testsuite/libgomp.c-c++-common/display-affinity-1.c	2018-10-08 13:43:45.226946161 +0200
@@ -10,7 +10,7 @@
 int
 main ()
 {
-#define FMT "L:%0.5L%%%n>%32h<!%.33{host}!%.6P_%T_%0.18T_%0.7{ancestor_tnum} %18a"
+#define FMT "L:%0.5L%%%n>%32H<!%.33{host}!%.6P_%i_%0.18i_%0.7{ancestor_tnum} %18A"
   char buf[] = FMT, hostname[256], buf2[512 + 32], *q;
   size_t l, l2, l3;
   char *r = getenv ("OMP_AFFINITY_FORMAT");
@@ -52,12 +52,12 @@ main ()
       if (strlen (hostname) != l)
 	abort ();
       l2 = omp_capture_affinity (NULL, 0,
-				 "%0.5{thread_level}%%%32{host}|||%.33h"
-				 "%0.7A%3N!%N!");
+				 "%0.5{nesting_level}%%%32{host}|||%.33H"
+				 "%0.7a%3N!%N!");
       if (l2 != (5 + 1 + (l > 32 ? l : 32) + 3 + (l > 33 ? l : 33)
 		 + 7 + 3 + 1 + 1 + 1))
 	abort ();
-      omp_set_affinity_format ("%.5L%%%32h|||%.33{host}%0.7{ancestor_tnum}"
+      omp_set_affinity_format ("%.5L%%%32H|||%.33{host}%0.7{ancestor_tnum}"
 			       "%3{num_threads}!%{num_threads}!");
       l3 = omp_capture_affinity (buf2, sizeof buf2, "");
       if (l3 != l2)
@@ -86,6 +86,6 @@ main ()
 	abort ();
     }
   #pragma omp parallel num_threads (4) proc_bind(spread)
-  omp_display_affinity ("%0.2A!%n!%.4L!%N;%a");
+  omp_display_affinity ("%0.2a!%n!%.4L!%N;%.2t;%0.2T;%{team_num};%{num_teams};%A");
   return 0;
 }
--- libgomp/testsuite/libgomp.fortran/display-affinity-1.f90.jj	2018-05-23 14:24:01.349865094 +0200
+++ libgomp/testsuite/libgomp.fortran/display-affinity-1.f90	2018-10-08 13:47:22.664311686 +0200
@@ -9,7 +9,7 @@
   character(len=1) :: buf4
   integer :: l1, l2
 
-  buf = 'L:%0.5L%%%n>%32h<!%.33{host}!%.6P_%T_%0.18T_%0.7{ancestor_tnum} %18a'
+  buf = 'L:%0.5L%%%n>%32H<!%.33{host}!%.6P_%i_%0.18i_%0.7{ancestor_tnum} %18A'
   call omp_set_affinity_format (format = buf)
   if (omp_get_affinity_format (buf4) /= 68) stop 1
   if (buf4 /= 'L') stop 2
@@ -19,7 +19,7 @@
   if (buf3 /= 'L:%0.5L%') stop 6
   call omp_display_affinity ('')
   call omp_display_affinity ('%%%0.9N')
-  l1 = omp_capture_affinity (buf4, '%0.5{thread_level}%%|||%0.7A%3N!%N!')
+  l1 = omp_capture_affinity (buf4, '%0.5{nesting_level}%%|||%0.7a%3N!%N!')
   buf = '%.5L%%|||%0.7{ancestor_tnum}%3{num_threads}!%{num_threads}!'
   call omp_set_affinity_format (trim (buf))
   l2 = omp_capture_affinity (buf2, '')
@@ -28,6 +28,7 @@
   if (buf2 /= '    0%|||-0000011  !1!') stop 9
   if (buf4 /= '0') stop 10
 !$omp parallel num_threads (4) proc_bind(spread)
-  call omp_display_affinity ('%0.2A!%n!%.4L!%N;%a')
+  call omp_display_affinity ('%0.2a!%n!%.4L!%N;%.2t;%0.2T;&
+                             &%{team_num};%{num_teams};%A')
 !$omp end parallel
 end


	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]