diff --git a/NEWS b/NEWS
index 66e65ff7e55db9921823fab0ad1396e9eef678c7..a77b0294be853f2fb4bfb02701638b1f78dc1e7a 100644
--- a/NEWS
+++ b/NEWS
@@ -383,6 +383,13 @@ documents those changes that are of interest to users and administrators.
  -- Fix for non-standard Munge port location for srun/pmi use.
  -- Fix gang scheduling/preemption issue that could cancel job at startup.
  -- Fix a bug in squeue which prevented squeue -tPD to print array jobs.
+ -- Sort job arrays in job queue according to array_task_id when priorities are
+    equal.
+ -- Fix segfault in sreport when there was no response from the dbd.
+ -- ALPS - Fix compile to not link against -ljob and -lexpat with every lib
+    or binary.
+ -- Fix testing for CR_Memory when CR_Memory and CR_ONE_TASK_PER_CORE are used
+    with select/linear.
 
 * Changes in Slurm 14.11.8
 ==========================
diff --git a/auxdir/x_ac_cray.m4 b/auxdir/x_ac_cray.m4
index c7befc9ee977ca941aec10921992bdbf0ab45db9..2e608eed2402738acd32df849bb98de33caa130f 100644
--- a/auxdir/x_ac_cray.m4
+++ b/auxdir/x_ac_cray.m4
@@ -220,14 +220,18 @@ AC_DEFUN([X_AC_CRAY],
     ac_have_real_cray="no"
   fi
   if test "$ac_have_alps_cray" = "yes"; then
-    # libexpat is always required for the XML-RPC interface
+    # libexpat is always required for the XML-RPC interface, but it is only
+    # needed in the select plugin, so set it up here instead of everywhere.
     AC_CHECK_HEADER(expat.h, [],
 		    AC_MSG_ERROR([Cray BASIL requires expat headers/rpm]))
-    AC_CHECK_LIB(expat, XML_ParserCreate, [],
+    AC_CHECK_LIB(expat, XML_ParserCreate, [CRAY_SELECT_LDFLAGS="$CRAY_SELECT_LDFLAGS -lexpat"],
 		 AC_MSG_ERROR([Cray BASIL requires libexpat.so (i.e. libexpat1-dev)]))
 
     if test "$ac_have_real_cray" = "yes"; then
-      AC_CHECK_LIB([job], [job_getjid], [],
+      # libjob is needed, but we don't want to put it on the LIBS line here.
+      # If we are on a native system it is handled elsewhere, and on a hybrid
+      # we only need this in libsrun.
+      AC_CHECK_LIB([job], [job_getjid], [CRAY_JOB_LDFLAGS="$CRAY_JOB_LDFLAGS -ljob"],
 	      AC_MSG_ERROR([Need cray-job (usually in /opt/cray/job/default)]))
       AC_DEFINE(HAVE_REAL_CRAY, 1, [Define to 1 for running on a real Cray system])
     fi
diff --git a/config.h.in b/config.h.in
index d9fc290c8c011e6106581c91b7ddbdc48b0ae91d..875c959315b385e78e08eff6bf88484d01ed1908 100644
--- a/config.h.in
+++ b/config.h.in
@@ -175,12 +175,6 @@
 /* Define to 1 if you have a functional curl library. */
 #undef HAVE_LIBCURL
 
-/* Define to 1 if you have the `expat' library (-lexpat). */
-#undef HAVE_LIBEXPAT
-
-/* Define to 1 if you have the `job' library (-ljob). */
-#undef HAVE_LIBJOB
-
 /* Define to 1 if you have the <limits.h> header file. */
 #undef HAVE_LIMITS_H
 
diff --git a/configure b/configure
index 878ab27c49230dc6f6f1e4517bcf648816dded83..bc86885bc047a1a51d075542ecd7ed735a8a50c0 100755
--- a/configure
+++ b/configure
@@ -22499,7 +22499,8 @@ $as_echo "$ac_have_alps_cray" >&6; }
     ac_have_real_cray="no"
   fi
   if test "$ac_have_alps_cray" = "yes"; then
-    # libexpat is always required for the XML-RPC interface
+    # libexpat is always required for the XML-RPC interface, but it is only
+    # needed in the select plugin, so set it up here instead of everywhere.
     ac_fn_c_check_header_mongrel "$LINENO" "expat.h" "ac_cv_header_expat_h" "$ac_includes_default"
 if test "x$ac_cv_header_expat_h" = xyes; then :
 
@@ -22545,18 +22546,16 @@ fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_expat_XML_ParserCreate" >&5
 $as_echo "$ac_cv_lib_expat_XML_ParserCreate" >&6; }
 if test "x$ac_cv_lib_expat_XML_ParserCreate" = xyes; then :
-  cat >>confdefs.h <<_ACEOF
-#define HAVE_LIBEXPAT 1
-_ACEOF
-
-  LIBS="-lexpat $LIBS"
-
+  CRAY_SELECT_LDFLAGS="$CRAY_SELECT_LDFLAGS -lexpat"
 else
   as_fn_error $? "Cray BASIL requires libexpat.so (i.e. libexpat1-dev)" "$LINENO" 5
 fi
 
 
     if test "$ac_have_real_cray" = "yes"; then
+      # libjob is needed, but we don't want to put it on the LIBS line here.
+      # If we are on a native system it is handled elsewhere, and on a hybrid
+      # we only need this in libsrun.
       { $as_echo "$as_me:${as_lineno-$LINENO}: checking for job_getjid in -ljob" >&5
 $as_echo_n "checking for job_getjid in -ljob... " >&6; }
 if ${ac_cv_lib_job_job_getjid+:} false; then :
@@ -22594,12 +22593,7 @@ fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_job_job_getjid" >&5
 $as_echo "$ac_cv_lib_job_job_getjid" >&6; }
 if test "x$ac_cv_lib_job_job_getjid" = xyes; then :
-  cat >>confdefs.h <<_ACEOF
-#define HAVE_LIBJOB 1
-_ACEOF
-
-  LIBS="-ljob $LIBS"
-
+  CRAY_JOB_LDFLAGS="$CRAY_JOB_LDFLAGS -ljob"
 else
   as_fn_error $? "Need cray-job (usually in /opt/cray/job/default)" "$LINENO" 5
 fi
diff --git a/src/plugins/select/linear/select_linear.c b/src/plugins/select/linear/select_linear.c
index 712be82dbfadb9c8ac8021278c1951b231699001..3c961aac5bd3fe15975686c391d42a920193bc85 100644
--- a/src/plugins/select/linear/select_linear.c
+++ b/src/plugins/select/linear/select_linear.c
@@ -482,7 +482,7 @@ static void _build_select_struct(struct job_record *job_ptr, bitstr_t *bitmap)
 	uint32_t job_memory_cpu = 0, job_memory_node = 0;
 	job_resources_t *job_resrcs_ptr;
 
-	if (job_ptr->details->pn_min_memory  && (cr_type == CR_MEMORY)) {
+	if (job_ptr->details->pn_min_memory  && (cr_type & CR_MEMORY)) {
 		if (job_ptr->details->pn_min_memory & MEM_PER_CPU)
 			job_memory_cpu = job_ptr->details->pn_min_memory &
 				(~MEM_PER_CPU);
@@ -564,7 +564,7 @@ static int _job_count_bitmap(struct cr_record *cr_ptr,
 	if (mode != SELECT_MODE_TEST_ONLY) {
 		use_total_gres = false;
 		if (job_ptr->details->pn_min_memory  &&
-		    (cr_type == CR_MEMORY)) {
+		    (cr_type & CR_MEMORY)) {
 			if (job_ptr->details->pn_min_memory & MEM_PER_CPU) {
 				job_memory_cpu = job_ptr->details->pn_min_memory
 					& (~MEM_PER_CPU);
@@ -2253,7 +2253,7 @@ static int _rm_job_from_nodes(struct cr_record *cr_ptr,
 	}
 
 	if (remove_all && job_ptr->details &&
-	    job_ptr->details->pn_min_memory && (cr_type == CR_MEMORY)) {
+	    job_ptr->details->pn_min_memory && (cr_type & CR_MEMORY)) {
 		if (job_ptr->details->pn_min_memory & MEM_PER_CPU) {
 			job_memory_cpu = job_ptr->details->pn_min_memory &
 				(~MEM_PER_CPU);
@@ -2661,7 +2661,7 @@ static int _rm_job_from_one_node(struct job_record *job_ptr,
 	}
 
 	if (job_ptr->details &&
-	    job_ptr->details->pn_min_memory && (cr_type == CR_MEMORY)) {
+	    job_ptr->details->pn_min_memory && (cr_type & CR_MEMORY)) {
 		if (job_ptr->details->pn_min_memory & MEM_PER_CPU) {
 			job_memory_cpu = job_ptr->details->pn_min_memory &
 				(~MEM_PER_CPU);
@@ -2748,7 +2748,7 @@ static int _add_job_to_nodes(struct cr_record *cr_ptr,
 	}
 
 	if (alloc_all && job_ptr->details &&
-	    job_ptr->details->pn_min_memory && (cr_type == CR_MEMORY)) {
+	    job_ptr->details->pn_min_memory && (cr_type & CR_MEMORY)) {
 		if (job_ptr->details->pn_min_memory & MEM_PER_CPU) {
 			job_memory_cpu = job_ptr->details->pn_min_memory &
 				(~MEM_PER_CPU);
@@ -3010,7 +3010,7 @@ static void _init_node_cr(void)
 		job_memory_cpu  = 0;
 		job_memory_node = 0;
 		if (job_ptr->details && job_ptr->details->pn_min_memory &&
-		    (cr_type == CR_MEMORY)) {
+		    (cr_type & CR_MEMORY)) {
 			if (job_ptr->details->pn_min_memory & MEM_PER_CPU) {
 				job_memory_cpu = job_ptr->details->
 					pn_min_memory &
diff --git a/src/slurmctld/job_scheduler.c b/src/slurmctld/job_scheduler.c
index ef8a066990f4ba809889c10ef145a51f091a34ee..38c3e9efbb3cf1bd1998c11e73dc87eb95488480 100644
--- a/src/slurmctld/job_scheduler.c
+++ b/src/slurmctld/job_scheduler.c
@@ -1763,6 +1763,7 @@ extern int sort_job_queue2(void *x, void *y)
 	bool has_resv1, has_resv2;
 	static time_t config_update = 0;
 	static bool preemption_enabled = true;
+	uint32_t job_id1, job_id2;
 	uint32_t p1, p2;
 
 	/* The following block of code is designed to minimize run time in
@@ -1814,7 +1815,21 @@ extern int sort_job_queue2(void *x, void *y)
 		return -1;
 
 	/* If the priorities are the same sort by increasing job id's */
-	if (job_rec1->job_id > job_rec2->job_id)
+	if (job_rec1->array_task_id == NO_VAL)
+		job_id1 = job_rec1->job_id;
+	else
+		job_id1 = job_rec1->job_ptr->array_job_id;
+	if (job_rec2->array_task_id == NO_VAL)
+		job_id2 = job_rec2->job_id;
+	else
+		job_id2 = job_rec2->job_ptr->array_job_id;
+	if (job_id1 > job_id2)
+		return 1;
+	else if (job_id1 < job_id2)
+		return -1;
+
+	/* If job IDs match compare task IDs */
+	if (job_rec1->array_task_id > job_rec2->array_task_id)
 		return 1;
 
 	return -1;
diff --git a/src/sreport/job_reports.c b/src/sreport/job_reports.c
index 9d6b89831fd74754bfea14bebf1a2082eb24a578..353808913976b93c5c22eeb8de61fd22c48bbf3b 100644
--- a/src/sreport/job_reports.c
+++ b/src/sreport/job_reports.c
@@ -631,6 +631,7 @@ static int _run_report(int type, int argc, char *argv[])
 	List header_list = NULL;
 	char *object_str = "";
 
+	/* init memory before chance of going to end_it before being init'ed. */
 	memset(&total_field, 0, sizeof(print_field_t));
 	print_fields_list = list_create(destroy_print_field);
 
diff --git a/src/srun/libsrun/Makefile.am b/src/srun/libsrun/Makefile.am
index 4011cf4ebb085b2e8c1a781f88c821b14f7e7cf6..910637ccf523982a50e3e840d1261a4b3bd16053 100644
--- a/src/srun/libsrun/Makefile.am
+++ b/src/srun/libsrun/Makefile.am
@@ -3,7 +3,8 @@
 AUTOMAKE_OPTIONS = foreign
 CLEANFILES = core.*
 
-AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/src/srun/libsrun
+AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/src/srun/libsrun \
+	 $(CRAY_JOB_CPPFLAGS)
 
 noinst_LTLIBRARIES = libsrun.la
 
@@ -16,7 +17,8 @@ libsrun_la_SOURCES = \
 	opt.c opt.h \
 	srun_job.c srun_job.h
 libsrun_la_LIBADD = $(DL_LIBS)
-libsrun_la_LDFLAGS  = $(LIB_LDFLAGS) -module --export-dynamic
+libsrun_la_LDFLAGS  = $(LIB_LDFLAGS) -module --export-dynamic \
+	$(CRAY_JOB_LDFLAGS)
 
 force:
 $(convenience_libs) : force
diff --git a/src/srun/libsrun/Makefile.in b/src/srun/libsrun/Makefile.in
index f416634bfbc4168bbba52e3537382eb4d7f51e9a..1f4016ac320f803b9e4bf2e2a477d5cb52f91f1f 100644
--- a/src/srun/libsrun/Makefile.in
+++ b/src/srun/libsrun/Makefile.in
@@ -458,7 +458,9 @@ top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
 AUTOMAKE_OPTIONS = foreign
 CLEANFILES = core.*
-AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/src/srun/libsrun
+AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/src/srun/libsrun \
+	 $(CRAY_JOB_CPPFLAGS)
+
 noinst_LTLIBRARIES = libsrun.la
 libsrun_la_SOURCES = \
 	allocate.c allocate.h \
@@ -470,7 +472,9 @@ libsrun_la_SOURCES = \
 	srun_job.c srun_job.h
 
 libsrun_la_LIBADD = $(DL_LIBS)
-libsrun_la_LDFLAGS = $(LIB_LDFLAGS) -module --export-dynamic
+libsrun_la_LDFLAGS = $(LIB_LDFLAGS) -module --export-dynamic \
+	$(CRAY_JOB_LDFLAGS)
+
 all: all-am
 
 .SUFFIXES: